我正在制作一个采矿游戏,如果你点击某处,你会删除放置在那里的区块。现在所有的块都是正方形,只有当我的2d布尔数组中的点为真时才绘制。因此,我试图将这个位置设置为false,只要您单击这里,就是我的inputprocessor
的触地方法。
private Vector2 tmp = new Vector2();
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
tmp.x = screenX / MapGrid.CELL_SIZE;
tmp.y = screenY / MapGrid.CELL_SIZE;
cam.unproject(new Vector3(tmp.x, tmp.y, 0));
grid.manipulateGrid((int)(tmp.x), (int)(tmp.y), false);
System.out.println("Clicked at: (" + tmp.x + ", " + tmp.y +")");
return false;
}
我也是翻译相机到我的球员位置。grid.manipulateGrid
接受x和y并将其设置为false。我的玩家位于(10,126)的网格坐标中,当我点击他旁边的时候,它说我正在点击(35,24),我不确定我是否做对了,但是我一直在到处搜索,找不到解决方案。我发现问题相似,但没有结果。如果有人能告诉我如何调整点击到球员的坐标,我会非常感激。
发布于 2015-10-19 18:14:37
你必须在取消投影后划分地图格。
@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;
}
发布于 2015-10-19 04:10:52
嗯,图纸的坐标和输入不一样。在LibGDX中输入的坐标从左上角开始为(0,0),在一般情况下,您绘制的世界坐标以及所有开始向下-左的坐标。所以你需要做的事情是:
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
tmp.x = screenX / MapGrid.CELL_SIZE;
tmp.y = (Gdx.graphics.getHeight() - screenY)/ MapGrid.CELL_SIZE;
cam.unproject(new Vector3(tmp.x, tmp.y, 0));
grid.manipulateGrid((int)(tmp.x), (int)(tmp.y), false);
System.out.println("Clicked at: (" + tmp.x + ", " + tmp.y +")");
return false;
}
有关更多信息,请阅读以下内容:https://gamedev.stackexchange.com/questions/103145/libgdx-input-y-axis-flipped
https://stackoverflow.com/questions/33206415
复制相似问题