Tile Layer with secondary tileset exports data with wrong indexes

Hi! I’ve used Tiled for a little while, but I am new to this forum.

I am using Tiled for my own game engine, and I noticed some unexpected behavior when exporting a map file with multiple tilesets. The first tileset index data works correctly, with the first tile starting at 1. The second tileset though begins at index 9. I have a feeling the second tileset indexes are simply added on top of the existing tileset, but this really messes with the way I am reading and parsing the final file.

Is there a way to force Tiled to start all tilesets at index 1?

Hope my explanation is sufficient.

Tiled assigns a different firstgid to each tileset, this is the way that tiles from different tilesets can be differentiated. If tile 0 from Tileset A was 1, and tile 0 from Tileset B was 1, how would you know which tileset the tile is from? However, if tiles 1-8 are Tileset A (firstgid = 1) and tiles 9+ are Tileset B (firstgid = 9), then you know which tileset each tile comes from.

The Tiled map file has the firstgids for all the tilesets listed along with the tileset, you need to use that value instead of assuming 1.

TMX and TMJ are built around global tile IDs, and you cannot change this. You can create your own custom formats via scripting, though - but keep in mind that you’ll need to come up with some way to distinguish tiles from different tilesets, and the firstgid approach is one of the simplest there is.

That makes sense, I had decided to only use one tileset per layer for simplicity’s sake, but I might as well implement multiple tileset support now. Did not know about the firstgid parameter, thank you.