Parse which tileset the tile is using

I"m parsing the tmx file directly as a XML file, and I was wondering if there is any way to know which tileset the tile is using? I see that If i’m using two tilesets it just puts as an attribute the “gid”, so there is no way I can guess which tileset is using

Hey @Elvis_L, welcome to the forums!

This part is covered by the following section in the manual:

Whatever format you choose for your layer data, you will always end up with so called “global tile IDs” (gids). They are global, since they may refer to a tile from any of the tilesets used by the map. In order to find out from which tileset the tile is you need to find the tileset with the highest firstgid that is still lower or equal than the gid. The tilesets are always stored with increasing firstgids.

You can scroll further down for a small code example of how this could be done. A linear search over the tilesets as done there will generally work out fine since most maps refer to only a few tilesets. Of course, you could also prepare an array or map to potentially make the lookup faster.

1 Like

Thank you very much! I was wondering if it was something like that, since the gid that a second tileset I was using was bigger than the higher gid I was getting from the first tileset, but I wanted to be sure, thank you very much!