Search code examples
libgdxtiled

Accesing a tile from tileset in tiled


I am trying to access a TextureRegion on a tile from a tileset in Tiled. The way I am accessing the tileset on my TiledMap is:

TiledMapTileSet tileset =  tiledMap.getTileSets().getTileSet("Tiles").getTile(0).getTextureRegion();

This works fine as long as the tileset is the first one referenced in the map. If I add another tileset called "Tiles2" and do the same:

TiledMapTileSet tileset =  tiledMap.getTileSets().getTileSet("Tiles2").getTile(0).getTextureRegion();

I just get null returned.

Trying with an index instead:

TiledMapTileSet tileset =  tiledMap.getTileSets().getTileSet(0).getTile(0).getTextureRegion();

Also only works with the first tileset.

Is this a bug? Working as intended? Or am I doing it wrong? It seems odd to have the feature to get a tileset by its index/name but only allow you to access one.


Solution

  • The answer here is that is does actualy work. The tiles in the second tileset is put in a map with a key. So when you accces the tile its not with an index but with a key.
    The key of the first tile in tileset 2 is therefore:

    [key of last tile in tileset1] + 1