Search code examples
libgdxtiled

Libgdx is showing wrong (x, y) coordinates from tiled


When i remove a tile with the coords (example: X: 15, Y: 9) with

TiledMapTileLayer tiledMapTileLayer = (TiledMapTileLayer)map.getLayers().get(0);
tiledMapTileLayer.setCell(15, 9, null);

I notice that actually the wrong tile is removed from the map. Instead tile with the coords X:15 Y: 6 is being removed. What am i doing wrong?


Solution

  • I believe this would be due to libgdx inverting the map to match better with their coordinate system. If your map is 16 tiles high, trying to remove tile at Y: 9 will result in removal of tile at Y: 16 - 9 - 1 = 6.

    If you want to copy a Y coordinate from Tiled and put it in your code, you'll in general need to apply the following conversion to turn it into the same location in libgdx:

    int y = tileLayer.getHeight() - 1 - [Y coordinate from Tiled];