输入未按指定的libgdx java工作
我有一个二维布尔阵列,映射块所在的位置(如果坐标为真,则块位于那里)。我正试图使它成为这样,如果你点击某个地方,它会将该位置设置为false。我的mapgrid的单元格大小为10,因此,如果在网格中单击(2001000),(20100)应该设置为false。下面是我如何在我的输入未按指定的libgdx java工作,java,libgdx,Java,Libgdx,我有一个二维布尔阵列,映射块所在的位置(如果坐标为真,则块位于那里)。我正试图使它成为这样,如果你点击某个地方,它会将该位置设置为false。我的mapgrid的单元格大小为10,因此,如果在网格中单击(2001000),(20100)应该设置为false。下面是我如何在我的InputListener @Override public boolean touchDragged(int screenX, int screenY, int pointer) { tmp.x = scr
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;
}
更改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;
}