Start every tileset ID from 0

So I have two tileset:

  • background
  • foreground

The background has 252 tiles (32x32) and foreground has like 100. On the Tiled application, the Properties tab shows the very first ID of the foreground as 0. OK, Cool. The background Tile ID is zero as well (as it should be).

But when I export the Map as JSON, the Tile ID on the Foreground changes. Instead of Zero it is now 253.

How do I make it so every tileset ID starts from zero instead of the last ID? This is so odd. I’m pretty new to Tiled and I don’t want to have to keep doing minus (last ID) to calculate correctly the ID.

Any help is appreciated.

You can’t do this, because you wouldn’t be able to determine from which tileset that particular tile is (not without additional knowledge at least: only you know that you have only two layers that only use a specific tileset for each).

The way to get from 253 to 0 is to subtract the “firstgid” associated with your second tileset. In the general case, this system allows a tile layer to use any number of tilesets. You can read more about this in the documentation (the JSON format works the same way).

Hi @bjorn. Thank you for responding. What if my map had two tilesets and two layers. One tileset belonging to each layer.

What about then?

It doesn’t matter, Tiled supports multiple tilesets per layer so it can’t change its output format to rely on there being only a single tileset per layer. It could be introduced as an option, but Tiled currently has no such option.

But, you can always implement your own map format, and teach Tiled how to read/write it by implementing either a C++ or Python Tiled plugin. Then you can simplify it as much as you like.