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