gpt4 book ai didi

java - 输入无法按指定的 libgdx java 工作

转载 作者:太空宇宙 更新时间:2023-11-04 13:19:32 25 4
gpt4 key购买 nike

我有一个二维 boolean 数组,它映射 block 所在的位置(如果坐标为真,则 block 位于那里)。我试图做到这一点,因此如果您单击某处,它会将该位置设置为 false,以便挖掘该 block 。我的 map 网格的单元格大小为 10,因此如果我单击 (200, 1000),网格中的 (20, 100) 应设置为 false。以下是我尝试在 InputListener

中实现此目的的方法
    @Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
tmp.x = screenX;
tmp.y = (Gdx.graphics.getHeight() - screenY);
tmp.z = 0;
cam.unproject(tmp);
grid.manipulateGrid((int)(tmp.x) / MapGrid.CELL_SIZE, (int)(tmp.y) / MapGrid.CELL_SIZE, false);
System.out.println("Clicked at: (" + tmp.x / MapGrid.CELL_SIZE + ", " + tmp.y / MapGrid.CELL_SIZE +")");
return false;
}

现在这几乎可以完美工作,但是 y 原点仍然是左上角,我以为我正在以初始化 tmp.y 的方式修复此问题,非常感谢任何帮助

最佳答案

像这样取消投影后更改 tmp.y 以更改局部坐标

    @Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
tmp.x = screenX;
tmp.y = screenY;
tmp.z = 0;
cam.unproject(tmp);
grid.manipulateGrid((int)(tmp.x) / MapGrid.CELL_SIZE, (int)(tmp.y) / MapGrid.CELL_SIZE, false);
System.out.println("Clicked at: (" + tmp.x / MapGrid.CELL_SIZE + ", " + (Gdx.graphics.getHeight() - tmp.y) / MapGrid.CELL_SIZE +")");
return false;
}

关于java - 输入无法按指定的 libgdx java 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33221150/

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