LibGDX-如何将坐标从(Android)屏幕转换为tileMap?

LibGDX-如何将坐标从(Android)屏幕转换为tileMap?,android,opengl-es,libgdx,Android,Opengl Es,Libgdx,我正在使用LibGdx和TileMap制作一个游戏。我希望地图显示在特定的屏幕坐标上,为按钮和文本留出一些空间。我在boardOffsetX,boardOffsetY变量中有这些坐标。我想在地图的顶部和底部做相同的Y偏移 我这样配置了一个视口: int width = Gdx.graphics.getWidth(); int height = Gdx.graphics.getHeight(); float s = (float)(height-boardOffsetY*2)/(float)hei

我正在使用LibGdx和TileMap制作一个游戏。我希望地图显示在特定的屏幕坐标上,为按钮和文本留出一些空间。我在boardOffsetX,boardOffsetY变量中有这些坐标。我想在地图的顶部和底部做相同的Y偏移

我这样配置了一个视口:

int width = Gdx.graphics.getWidth();
int height = Gdx.graphics.getHeight();
float s = (float)(height-boardOffsetY*2)/(float)height; // keep aspect ratio
Gdx.gl.glViewport(boardOffsetX, boardOffsetY, (int)(width*s), height-boardOffsetY*2);
camera.update();
batch.begin();
renderer.setView(camera);
renderer.render();
Vector3 tile = new Vector3(gameTileSize,gameTileSize,0);
tile = camera.project(tile);
projectedtilesize = tile.x;  // tiles are square, so no matter x or y
到目前为止,效果良好,贴图渲染效果良好。现在我想知道用户单击了哪个磁贴。目前我找到了两种方法来实现这一点——将触摸协调后投射到屏幕上,或者将实际的瓷砖大小投射到屏幕上,并以此作为度量

第二种方法是这样的:

int width = Gdx.graphics.getWidth();
int height = Gdx.graphics.getHeight();
float s = (float)(height-boardOffsetY*2)/(float)height; // keep aspect ratio
Gdx.gl.glViewport(boardOffsetX, boardOffsetY, (int)(width*s), height-boardOffsetY*2);
camera.update();
batch.begin();
renderer.setView(camera);
renderer.render();
Vector3 tile = new Vector3(gameTileSize,gameTileSize,0);
tile = camera.project(tile);
projectedtilesize = tile.x;  // tiles are square, so no matter x or y
现在我知道了屏幕上瓷砖的大小。在回调中,我可以测量屏幕:

public boolean tap(float x, float y, int count, int button) {
     float dx = x - boardOffsetX;
     float dy = y - boardOffsetY;
     final int tx = (int) (dx / projectedtilesize);
     final int ty = (int) (dy / projectedtilesize);
而且。。。它不起作用。屏幕上的瓷砖大小不同。不多,但不同。 我也试着用

camera.unproject(clickCoordinates)
结果完全一样。我做错了什么,为什么我的瓷砖的尺寸会投影到屏幕上并返回结果,而不是通过渲染方法生成的