gpt4 book ai didi

java - LibGDX down为up up为down gdx.input.getY()

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:48:23 25 4
gpt4 key购买 nike

我敢肯定这是非常简单的事情。我的大脑严重卡住。我一直在反转它,从中减去,乘以它,添加到它。不管是上是下还是下是上。

if (Gdx.input.isButtonPressed(Buttons.LEFT)) s.drawCirc(c, Gdx.input.getX(), Gdx.input.getY(), 100, 100);

x 轴很好,罪魁祸首是 Gdx.input.getY()。当我向上移动手指时,它会向下移动,向下移动时会向上移动。

我的圆圈在中间排成一行,但当我向上时它会下降,当我向下时它会上升。我想了解这里到底发生了什么以及为什么会发生。(当然还有如何修复它)

如果你需要知道 c 是我的相机,这里是代码以防这是罪魁祸首

c = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

在我使用的drawCirc 方法中

shapeRenderer.setProjectionMatrix(c.combined);

最佳答案

这是因为用于输入的坐标系和相机使用的坐标系在y轴上是相反的。理想情况下,在获取输入时,您希望将输入取消投影到相机,以便所有坐标都很好地对齐。您可以使用 c.unproject(input) 执行此操作。这是一个代码示例:

if (Gdx.input.isButtonPressed(Buttons.LEFT))
{
Vector3 input = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
cam.unproject(input);
//Now you can use input.x and input.y, as opposed to Gdx.input.getX() and
//Gdx.input.getY(), to draw the circle
s.drawCirc(c, input.x, input.y, 100, 100);
}

关于java - LibGDX down为up up为down gdx.input.getY(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23144655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com