Tiled appears to be replacing certain tiles with nonexistent ids


Some of my tiles in my map appear to be working and fine in the editor, but when I export it to JSON, the definition for the tile id just doesn’t exist in the tileset file. Why is this? How do I fix this?
Edit: This only happens when they are the tile before a blank space or tile. I’m subtracting firstgid to get the tile id right.

(Thorbjørn Lindeijer) #2

Hmm, no idea what could be happening here. Can Tiled itself load back the JSON file properly? If so then there is more likely some problem with the way you are loading the data.

Could it be that you’ve flipped a tile, which is exported by using the high bits in the global tile IDs, leading to very large numbers? Though that wouldn’t explain why this would only happen before a black space.


This reminds me of one my initial development stages where I was figuring out if I could depend on Tile IDs to reference a tilesheet externally. I don’t know if that’s the case here, but I’ll explain my experience just in case it proves useful.

Tiled’s Tile ID is ‘volatile’, in such a way that during the development of a map, through adding and deleting sprites, the tiles’ IDs will change and it breaks the original sequence. That means I couldn’t assume that referencing tile ID # 9 (ie tile_id - firstgid) refers to the 9th image in the tileset. In fact, there could be no ID # 9. There have been situations where I’ve gotten broken sequences, like 1, 3, 7, 10, etc.

So what I’ve learned is that there is no implicit mapping between Tile IDs and the integer sequence in which images appear in a tilesheet. You’d need to lookup a given Tile ID back in the TMX/JSON, and query the source attribute.

My game engine is C2, and I’m fortunate the 3rd-party TMX loader I’m using already allows me to populate a TMX Class object with the source image so that for any given tile, I know the source image path, and use that to instantiate my sprite.

(Thorbjørn Lindeijer) #4

This is correct for image collection tilesets, since when you remove an image it doesn’t change the IDs of any other tiles, affectively creating a gap in the ID sequence. This is to make sure references to the other tiles (which could be in maps that aren’t currently open) don’t break.

For tilesets based on a tileset image, the ID simply works as an index and there are no gaps.


I see! Ok that makes sense. Thanks for that information and clarification. For my project, I have had to use image collection exclusively, so I didn’t appreciate the difference.