2

I have a strange response with getProperties().get("value").

You can see below my tmx file and values provided by my program.

 <objectgroup name="objects">   <object id="1" name="player" type="player" x="256" y="3072" width="1290" height="1290">    <properties>
    <property name="name" value="Ahhhh"/>
    <property name="nom" value="Bhhhh"/>
    <property name="velocity" value="1.0"/>    </properties>   </object>  </objectgroup>

Source code

    MapObject mapPlayer = currentMap.getLayers().get("objects").getObjects().get("player");
MapObjects mapObject = currentMap.getLayers().get("objects").getObjects();
for (Iterator<String> iter = mapPlayer.getProperties().getKeys(); iter.hasNext(); )
{
    System.out.println("#############"+iter.next());
}
System.out.println("**************** player name :  " + mapPlayer.getProperties().get("name", String.class));
RectangleMapObject rect = (RectangleMapObject) mapObject.get("player");
float x = (float) rect.getRectangle().x;
float y = (float) rect.getRectangle().y;
float width = rect.getRectangle().width;
float height = rect.getRectangle().height;

System.out.println("**************** player coordinates X :  " +x);
System.out.println("**************** player coordinates Y:  "+y);
System.out.println("**************** player coordinates width :  " +width);
System.out.println("**************** player coordinates height:  "+height);
System.out.println("**************** player coordinates X :  " +mapPlayer.getProperties().get("x", Integer.class));
System.out.println("**************** player coordinates Y:  "+mapPlayer.getProperties().get("y", Integer.class));
System.out.println("**************** player velocity :  "+mapPlayer.getProperties().get("velocity", Integer.class));
#######width #######name #######nom #######id #######velocity #######height #######x #######y #######type

**************** player name : Ahhhh **************** player coordinates X : 256.0 **************** player coordinates Y: 3318.0 **************** player coordinates width : 1290.0 **************** player coordinates height: 1290.0 **************** player coordinates X : 256.0 **************** player coordinates Y: 3318.0 **************** player velocity : 1.0

Why Y hasn't show the correct value ?

Thanks

Furby
  • 23
  • 3

1 Answers1

1

It's probably because libgdx has the Y axis the other way around (pointing upwards instead of downwards like in Tiled) and is trying to be helpful by automatically converting the Y coordinates into its own coordinate space when loading the map.

Thorbjørn Lindeijer
  • 2,022
  • 1
  • 17
  • 22
  • Exactly, this is the reason. I didn't understand because it's easy to understand if width & height are a tile multiple (256 in my case), but if it's another value it can be more complex. Obviously Y is inverted. Thanks. – Furby Mar 02 '16 at 07:55