Java Libgdx-Actor';s的位置不正确
我在拔头发。我已经花了几个小时在这上面了。这就是我正在做的。我有一个演员的形象。我可以将此图像移动到我想要的任何地方。那很好。我添加了一个滑块,这样我也可以调整此图像的大小。这就是问题所在。一旦我调整它的大小,我仍然可以移动它,但它不再是我的手指所在的位置。它是,如果它的大小缩小,到东北。如果它增加了,则是SE。(指我的手指)。不管怎样,我不知道是什么原因造成的。我花了一个小时写了不同的公式来调整每种尺寸,但什么都不起作用。此外,世界范围也变得不正确。我不应该被允许将演员/图像移出屏幕。我做一个简单的检查。(actor.getX()只是浏览一下您的代码,看起来调整大小的滑块正在调整图像大小,而不是容器。我在处理圆并在圆上绘制图像时遇到了类似的情况;点击框和图像无法对齐。可怕的图片,即将出现! float xAspect=stage.getWidth()/Gdx.graphics.getWidth() float yAspect=stage.getHeight()/Gdx.graphics.getHeight()Java Libgdx-Actor';s的位置不正确,java,math,input,drag-and-drop,libgdx,Java,Math,Input,Drag And Drop,Libgdx,我在拔头发。我已经花了几个小时在这上面了。这就是我正在做的。我有一个演员的形象。我可以将此图像移动到我想要的任何地方。那很好。我添加了一个滑块,这样我也可以调整此图像的大小。这就是问题所在。一旦我调整它的大小,我仍然可以移动它,但它不再是我的手指所在的位置。它是,如果它的大小缩小,到东北。如果它增加了,则是SE。(指我的手指)。不管怎样,我不知道是什么原因造成的。我花了一个小时写了不同的公式来调整每种尺寸,但什么都不起作用。此外,世界范围也变得不正确。我不应该被允许将演员/图像移出屏幕。我做一个
这就是你的代码中让我感到疑惑的地方。不确定,但我记得拖动图像有一个ofset,因此如果你用手指在平板电脑上触摸拖动它,你可以看到它。但我不知道你是否可以以某种方式更改它。是的!这就是它的真实情况!因此它周围的虚拟框没有改变,这是导致问题的原因吗?是的till是否将框应用于原始大小?请检查我的编辑!查看是否将xAspect和yAspect更改为Button.getWidth而不是stage.getWidth,或者想出一种方法来调整图像和容器的大小。好的。我一回到家就会这样做,让你知道它是如何工作的。无论屏幕大小,x/yAspect都是如此t将根据屏幕分辨率正确转换。我是否也应该为按钮制作另一个x/Y透视图?尝试将舞台w/h替换为按钮的,但没有成功。:/以下是我认为正在发生的情况。您的第一个评论是正确的;“框”(舞台)中的图像正在调整大小,但由于阶段本身没有更改,因此它正在根据设置的阶段大小绘制图像,从而导致此问题。在我发布的图像中,图像使用右上角作为调整大小的参考点。如果您希望它正确调整大小,则需要同时将更改应用于阶段和图像。使用float xAspect=stage.getWidth()/Gdx.graphics.getWidth();将返回相同的框大小,因为stage从未更改。有意义吗?
private Table buildSlidersLayer() {
Table layer = new Table();
layer.right().top();
Label label = new Label("A Button Size", skinLibgdx);
layer.add(label);
layer.row();
sldSize = new Slider(0.0f, 1.0f, 0.01f, false, skinLibgdx);
layer.add(sldSize);
sldSize.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
sldSizeVal = sldSize.getValue();
divFacAButton = ((((1.0f - sldSizeVal) - 0.01f) * (2.0f - 0.7f)) / (0.99f - 0.01f)) + 0.7f;
aButton.setSize(120 / divFacAButton, 120 / divFacAButton);
}
});
// sldSize.setPosition(60, 60);
return layer;
}
aButton = new Image(skinCydeonWorld, "a-button");
layer.addActor(aButton);
aButton.setSize(aButton.getWidth() / 1.5f,
aButton.getHeight() / 1.5f);
aButton.setOrigin(aButton.getWidth() / 2, aButton.getHeight() / 2);
aButton.setPosition(GamePreferences.instance.aButtonX,
GamePreferences.instance.aButtonY);
aButton.setRotation(180f);
aButton.addListener(new DragListener() {
@Override
public void touchDragged(InputEvent event, float x, float y,
int pointer) {
float xAspect = stage.getWidth() / Gdx.graphics.getWidth();
float yAspect = stage.getHeight() / Gdx.graphics.getHeight();
aButton.setPosition(
(Gdx.input.getX() - aButton.getHeight() / 2f) * xAspect,
((Gdx.graphics.getHeight() - Gdx.input.getY()) - aButton
.getHeight() / 2f) * yAspect);
checkAndAdjustPos(aButton);
super.touchDragged(event, x, y, pointer);
}
});
aButton.addListener(new DragListener() {
@Override
public void touchDragged(InputEvent event, float x, float y,
int pointer) {
xAspect = Constants.VIEWPORT_GUI_WIDTH / Gdx.graphics.getWidth();
yAspect = Constants.VIEWPORT_GUI_HEIGHT/ Gdx.graphics.getHeight();
aButton.setPosition(
(Gdx.input.getX() - (aButton.getWidth() * divFacAButton / 2f))
* xAspect,
((Gdx.graphics.getHeight() - Gdx.input.getY()) - (aButton
.getHeight() * (divFacAButton < 1.3f ? 0f : divFacAButton) / 2f))
* yAspect);
checkAndAdjustPos(aButton);
super.touchDragged(event, x, y, pointer);
}
});
{
if (actor.getX() - (aButton.getWidth() / 2 / divFacAButton) + 80f / 2f < 0)
actor.setPosition(
(aButton.getWidth() / 2 / divFacAButton) - 80f / 2f,
actor.getY());
if (actor.getX() + actor.getWidth()
/ (minSize + maxSize - divFacAButton) > stage.getWidth() * xAspect)
actor.setPosition(stage.getWidth() * xAspect - actor.getWidth()
/ (maxSize + minSize - divFacAButton), actor.getY());
if (actor.getY() - (aButton.getHeight() / 2 / divFacAButton) + 80f / 2f < 0)
actor.setPosition(actor.getX(),
(aButton.getWidth() / 2 / divFacAButton) - 80f / 2f);
if (actor.getY() + actor.getHeight()
/ (minSize + maxSize - divFacAButton)/* / divFactor */> maxHeight * yAspect)
actor.setPosition(actor.getX(), maxHeight * yAspect - actor.getHeight()
/ (minSize + maxSize - divFacAButton));
}
xPosition - (1/2currentWidth / divFacAButton) + 1/2defaultWidth = leftEdge
yPosition - (1/2currentHeight / divFacAButton) + 1/2defaultHeight = bottomEdge