Click to move on tilemap

I am looking around trying to find the best way to display a general Tiled tilemap and then make each tile clickable so that I can use the clicked tile to pathfind the player to it. I am good with A* and all of that, but I am having a surprising time trying to figure out what tile the player has clicked on. I looked-through the documentation on Tile, which seems to be the low-level class that the tilemap will be made up of but didn’t find anything (unless it was right in front of me, which does happen a startling amount of the time these days).

Do I set a click event on each tile? That seems like it would be very inefficient. Or is this typically just done with calculations based on where in the canvas the user clicked and calculate with scroll offset, etc. to get the tile clicked? Are there any examples of this anywhere? Thanks!

Tilemap layers have methods which allow you to convert world coordinates of a given Camera to tile coordinates on the layer - worldToTileX, worldToTileY, and worldToTileXY. If you can figure out where on the world the player has clicked, you can figure out the position’s tile coordinates. Note that Pointers can also give you world coordinates.

1 Like

Thank you! That is what I was looking for. Not sure why I didn’t look at the layer level.