1
\$\begingroup\$

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>
\$\endgroup\$
1
\$\begingroup\$

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");

Find your objects

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.

\$\endgroup\$
0
\$\begingroup\$

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

Please see Add handling of in in the com.badlogic.gdx.maps.tiled package #3751 and Tiled map tiles objects support #4542 for details.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.