# LibGDX Tiled Map - how to get embedded objects

I am using LibGDX to learn Game Development. I have reached the phase I am learning to use Tiled Maps.

In Tiled map editor, there is a feature where we can pick a tile in the tile set, go to View -> Tile Collision Editor, and add shape objects to a tile.

I can see that the shapes are saved in the tmx file and associated to the tile.

For testing purpose, I have also made the tile animated (similar option is available under view menu) and the OrthogonalTiledMapRendered automatically animated it (so this information is being accessed somehow).

I wanted to find out if there is anyway to retrieve other information embedded at tile level like the embedded shapes and objects.

Here is the sample xml from the tmx file.

<tile id="7">
<properties>
<property name="customProp1" value="customValue1"/>
</properties>
<image width="16" height="16" source="black_hole_swallow_4.png"/>
<objectgroup draworder="index">
<object id="0" x="0.25" y="0">
<polyline points="0,0 15.625,-0.25"/>
</object>
</objectgroup>
<animation>
<frame tileid="5" duration="300"/>
<frame tileid="7" duration="200"/>
</animation>
</tile>


There are documents in libGDX's github wiki https://github.com/libgdx/libgdx/wiki/Tile-maps According to this page, you can get your objects by finding the layer contains them.

MapLayer layer = map.getLayers().get("my-layer");


MapObjects objects = layer.getObjects();


And get the object

objects.get("object_name");


There are many information you can get from the object

String name = object.getName();
float opacity = object.getOpacity();
boolean isVisible = object.isVisible();
Color color = object.getColor();


For more details you can go to the link above.

There are many more functions, like checking if the object is RectangleMapObject or PolygonMapObject etc.

• Why is this answer accepted? This does not work. Embedded collision objects inside tile layers can't be fetched, because LibGDX simply does not set the MapObjects from tilelayers. You can only achieve this by overriding BaseTmxMapLoader#loadTileLayer() and make sure the MapObjects also get stored. Or add a manual collision object layer inside Tiled. – Tipsi Dec 15 '19 at 21:44

LibGDX doesn't support <objectgroup> inside <tile>, yet. However, it could come, soon.

• If the details are relevant to the answer, please include them, here. – Gnemlock Jul 21 '17 at 7:40