# Anyone know how to use TMX in libGDX?

**URL:** <https://discourse.mapeditor.org/t/anyone-know-how-to-use-tmx-in-libgdx/917>\
**Category:** Questions\
**Created:** [November 13, 2015, 2:12am UTC](https://discourse.mapeditor.org/t/anyone-know-how-to-use-tmx-in-libgdx/917 "2015-11-13T02:12:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![supermoneylife](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/supermoneylife/32/2653_2.png) [@supermoneylife](https://discourse.mapeditor.org/u/supermoneylife)\
**Post date:** [November 13, 2015, 2:12am UTC](https://discourse.mapeditor.org/t/anyone-know-how-to-use-tmx-in-libgdx/917/1 "2015-11-13T02:12:33Z")

</div>

Hi all, Im having real trouble getting use of my Object Layers in TMX files within my libGDX project. I can load the file and it draws the Tile Layers images, but I need to get the Y coordinate for each of the platforms I placed in the Tiled project.

Here is the TMX file:

```
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="right-up" width="20" height="5" tilewidth="256" tileheight="256" nextobjectid="47">
 <tileset firstgid="1" name="bg" tilewidth="256" tileheight="256" tilecount="12">
  <image source="../textures/bg.jpg" width="1024" height="768"/>
 </tileset>
 <tileset firstgid="13" name="platforms" tilewidth="256" tileheight="256" tilecount="2">
  <tile id="0">
   <image width="256" height="256" source="../textures/tiles-brown.png"/>
  </tile>
  <tile id="1">
   <image width="256" height="256" source="../textures/tiles-green.png"/>
  </tile>
 </tileset>
 <layer name="background" width="20" height="5">
  <data encoding="base64" compression="zlib">
   eJytybkNADAIBEH/f//1ehMnyBCBNMGxIfheQURCdthWe79fT0qvaOgYYltN2xMLG0dsq2n7AsAQAbY=
  </data>
 </layer>
 <objectgroup name="platforms">
  <object id="20" name="floorRect" type="rectie" gid="14" x="1280" y="1280" width="256" height="256"/>
  <object id="21" name="floorRect" type="rectie" gid="14" x="1792" y="1280" width="256" height="256"/>
  <object id="22" name="floorRect" type="rectie" gid="14" x="1536" y="1280" width="256" height="256"/>
  <object id="23" name="floorRect" type="rectie" gid="13" x="2304" y="1280" width="256" height="256"/>
  <object id="24" name="floorRect" type="rectie" gid="13" x="2560" y="1280" width="256" height="256"/>
  <object id="25" name="floorRect" type="rectie" gid="14" x="2816" y="1280" width="256" height="256"/>
  <object id="26" name="floorRect" type="rectie" gid="14" x="2560" y="1024" width="256" height="256"/>
  <object id="27" name="floorRect" type="rectie" gid="14" x="2304" y="1024" width="256" height="256"/>
  <object id="28" name="floorRect" type="rectie" gid="14" x="3328" y="1280" width="256" height="256"/>
  <object id="29" name="floorRect" type="rectie" gid="14" x="3584" y="1024" width="256" height="256"/>
  <object id="30" gid="13" x="3584" y="1280" width="256" height="256"/>
  <object id="31" name="floorRect" type="rectie" gid="14" x="3840" y="1280" width="256" height="256"/>
  <object id="32" name="floorRect" type="rectie" gid="14" x="4096" y="1280" width="256" height="256"/>
  <object id="33" name="floorRect" type="rectie" gid="14" x="4352" y="1280" width="256" height="256"/>
  <object id="34" name="floorRect" type="rectie" gid="14" x="4608" y="1280" width="256" height="256"/>
  <object id="35" name="floorRect" type="rectie" gid="14" x="0" y="1280" width="256" height="256"/>
  <object id="36" gid="14" x="256" y="1280" width="256" height="256"/>
  <object id="37" name="floorRect" type="rectie" gid="14" x="512" y="1280" width="256" height="256"/>
  <object id="38" name="floorRect" type="rectie" gid="14" x="768" y="1280" width="256" height="256"/>
  <object id="39" gid="13" x="1024" y="1280" width="256" height="256"/>
  <object id="40" name="floorRect" type="rectie" gid="14" x="1024" y="1024" width="256" height="256"/>
  <object id="41" gid="14" x="0" y="1279" width="256" height="256"/>
  <object id="42" name="floorRect" type="rectie" gid="14" x="256" y="1280" width="256" height="256"/>
 </objectgroup>
</map>

```

And here is my libgdx Level class snippet (btw- I know this is completely wrong! It’s one of many things I’ve tried and I’m completely lost now):

platformRects = new Array();

```
    mapLayer1 = (TiledMapTileLayer)map.getLayers().get(1);
    objects = mapLayer1.getObjects();
    for (int i = 0; i < (mapLayer1.getWidth() / mapLayer1.getTileWidth()); i++){
        for (int n = 0; n < (mapLayer1.getHeight() / mapLayer1.getTileHeight()); n++){
            objects.getByType(rectie,platformRects);

        }

    }

```

The main thing I am stuck on is the calls and code I need to make to get the x coordinate from the TMX file and put them into an array so I can pass that info into the Platform class and then create all the blocks in the right place. I was told the getObjects() on the layer will do this but I have no clue how to go about it

---

<div class="post-metadata">

**Author:** ![supermoneylife](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/supermoneylife/32/2653_2.png) [@supermoneylife](https://discourse.mapeditor.org/u/supermoneylife)\
**Post date:** [November 15, 2015, 12:28am UTC](https://discourse.mapeditor.org/t/anyone-know-how-to-use-tmx-in-libgdx/917/2 "2015-11-15T00:28:05Z")

</div>

Thanks for no help! :\

---

<div class="post-metadata">

**Author:** ![Ablu](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/ablu/32/1496_2.png) [@Ablu](https://discourse.mapeditor.org/u/Ablu)\
**Post date:** [November 15, 2015, 9:47am UTC](https://discourse.mapeditor.org/t/anyone-know-how-to-use-tmx-in-libgdx/917/3 "2015-11-15T09:47:04Z")

</div>

> [@supermoneylife](#):
>
> Thanks for no help! :\

Well… you asked a question about implementiation details of a very specific library. Maybe you have a better chance to get a reply if you ask the community of that library.

---

<div class="post-metadata">

**Author:** ![supermoneylife](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/supermoneylife/32/2653_2.png) [@supermoneylife](https://discourse.mapeditor.org/u/supermoneylife)\
**Post date:** [November 15, 2015, 11:34am UTC](https://discourse.mapeditor.org/t/anyone-know-how-to-use-tmx-in-libgdx/917/4 "2015-11-15T11:34:57Z")

</div>

Just in case any poor souls stumble across this thread with a similar issue. I have it solved on this forum here: [http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=21068](http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=21068)

Basically the RectangleMapObject in libgdx doesn’t ‘see’ the objects placed with Tiled using the ‘Place Tile’ option within the Objects Layer, If I then manually draw rectangles using Tiled’s Rectangle Objects my code works a treat.

Peace 😉 … And btw, Tiled (/Bjorn and etc), thanks very very much for this helpful tool
