So I have been using Tiled map editor to create my map for my game. I'm using Libgdx to load and draw the map.

The problem is that the coordinate from objects placed in tiled do not seem to be the same when they are using in my game. It seems to be just the y value, as I have tried a few different positions and the x value seems to be okay.

I think it may be because Libgdx coordinate systems starts in the bottom left instead of the top left, but I'm not sure. And I'm not sure how to get around it.

In Tiled: enter image description here

In game: enter image description here

The black square is being drawn at the x and y values grabbed from the object.

I get the values from this function once the map loads:

    public Vector2 getStartingPosition()
    for (TiledObjectGroup group : map.objectGroups) {
        for (TiledObject object : group.objects) {
            if ("playerSpawn".equals(object.name)) 
                return new Vector2(object.x, object.y);

    //Was not found, return default spawn
    return new Vector2(0,0);
  • \$\begingroup\$ "I think it may be because Libgdx coordinate systems starts in the bottom left instead of the top left" I think you could be right. Does it change the position of other boxes? I see you have collision boxes? (red)? are they in the correct spot once loaded and rendered? or is it only the objects layer that is off? \$\endgroup\$
    – Savlon
    Feb 11 '13 at 7:16
  • \$\begingroup\$ It's only the object layer that seems to be off. The map seems to be drawn properly. I haven't even tried the collision layer yet, I'll give that a shot and see what happens. \$\endgroup\$
    – Milkboat
    Feb 11 '13 at 12:30
  • \$\begingroup\$ Okay, I tested the collision layer and the coordinates seem to be off for that layer aswell. \$\endgroup\$
    – Milkboat
    Feb 11 '13 at 13:34
  • \$\begingroup\$ Not sure if this helps, but try flipping the y axis : return new Vector2(object.x, -object.y); \$\endgroup\$
    – Sidar
    Feb 11 '13 at 14:06
  • \$\begingroup\$ Nope, didn't work. Made it wildly out of place :P \$\endgroup\$
    – Milkboat
    Feb 11 '13 at 14:08

Thanks for everyones help, but I have found the answer on another forum. I thought I would post the answer here for anyone else who may have issue:

You need to set the y value of the object to:

y = mapHeight - tilesize - y;

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.