Image based tilesets on know next ID

This isn’t really a bug, but tilesets that are made from images don’t know the next tile id, so it’s impossible to know the last tile id without iterating the whole set. My image based tileset has gaps in it due to deleting old tiles and there is no quick way to know the last id of the images in the tileset. I need to know this so I can tell if the tile came from the image tileset or not and I use the tile id ranges for this information.

You should generally not use the last tile ID for this, but the first ID. This is because tilesets can be expanded, which would increase the last ID. So if you use the last ID, you risk resolving the tiles to the wrong tileset when loading the map.

This is why Tiled stores the first global ID ("firstgid" attribute) with each tileset. When determining which tileset a certain global tile ID is referencing, you need to look for the tileset with the highest firstgid that is still lower or equal to the global tile ID (see the documentation).

I was hoping to not have to iterate the tiles sets just to find the last tile… but if that’s what I have to do. :slight_smile:

No, I’m saying you shouldn’t have a need for finding the last tile at all. To find out which tileset a tile is from, you should be using the first tile ID, not the last one. Maybe try reading my answer again.

Yes, I read your answer, this still requires me to iterate through the other tilesets to find their last ID. Due to how my converter works (it doesn’t know anything about the other tilesets), this is not convenient and I was trying to avoid it. As it seems like the only way, I’ll do that. I was just hoping each tileset stored a lastid. Thanks for the answer.

I still don’t understand what you need the last ID for. What you need is the first ID of the next tileset, right?

That’s the problem… I don’t know the next tileset. All I know is the tileid I’m looking up and the first id of the image tileset and I need to know of the this tileid is in the image tileset or not. I don’t know anything about the other tilesets. This is all for a very convoluted build process that I may need to rethink. Thanks for your help, but don’t waste anymore brain-space on this problem. I was just hoping for a simple solution to the process I’ve boxed myself into.

1 Like