Getting tile properties from TiledMapTile?

Suppose I have a TiledMapTile, and I want to get the Tile properties for that tile. I know that properties are located in the TiledMapTilesetTile object, but how do I get the TiledMapTilesetTile that corresponds to a TiledMapTile. I’ve spent a while digging into the code but still haven’t been able to figure it out, if anyone can assist then thank you in advance!

Hey @Sopheria

That’s a really good question. Unfortunately the library is a little lacking in this area but thanks for bringing it up so we can do something about it. Essentially we’ve modeled the classes to match the map format as it appears in the XML. I realize this isn’t especially useful when you’re trying to query things in a natural kind of way.

In the mean time, let me explain how it works so you might be able to come up with a workaround.

The Tiled map format has a few different elements relevant to what you’re trying to do. It’s essentially structured like this:

  • map
    • tilesets
      • tileset tiles
    • layers
      • tiles

Each map has multiple tilesets and multiple layers. Each layer has many tiles.

Each Tile has a Global Identifier (GID) and each Tileset Tile has a Local Identifier (LID).
A Tileset also has a First Identifier (FID).

I believe (from memory) that you can calculate the GID by adding the FID to the LID. In this way, you should be able to figure out what Tileset Tile is used in each Tile of the map. Make sense?

That’s about all I can tell you right now without looking into it a little deeper. I’ll add it to my to-do list to make the API a bit nicer in this area. I’d be interested to know your thoughts on how you’d like it to work?


Okay, that makes sense. So would the local identifier be the index that the TilesetTile is stored under in TiledMapTileset’s IReadOnlyList Tiles property?

I think a nice clean API would be to have the TiledMapTile store a pointer to the TiledMapTilsetTile instead of a global identifier. But I can work with this, it’s not too bad, I was just having a hard time figuring it out.

Thank you for your response, @craftworkgames!

Use TiledMapTileset.Contains...(int globalIdentifier) and TiledMapTileset.GetAnimatedTilesetTileBy...(int localTileIdentifier).

If you don’t know the tileset in advance you will have to iterate through all of them to find the one that contains the global identifier.

@LithiumToast What do I do when the tile I’m trying to get isn’t an animated tile?

For now, look through TiledMapTileset.Tiles list looking for the tile you want. It is possible to use a dictionary in the some fashion as animated tiles to make things a little easier, but that will come later.

@LithiumToast Awesome. I had asked about that in my second post. Thank you for the assistance.