1
\$\begingroup\$

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);
}
\$\endgroup\$
7
  • \$\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
    Commented Feb 11, 2013 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
    Commented Feb 11, 2013 at 12:30
  • \$\begingroup\$ Okay, I tested the collision layer and the coordinates seem to be off for that layer aswell. \$\endgroup\$
    – Milkboat
    Commented Feb 11, 2013 at 13:34
  • \$\begingroup\$ Not sure if this helps, but try flipping the y axis : return new Vector2(object.x, -object.y); \$\endgroup\$
    – Sidar
    Commented Feb 11, 2013 at 14:06
  • \$\begingroup\$ Nope, didn't work. Made it wildly out of place :P \$\endgroup\$
    – Milkboat
    Commented Feb 11, 2013 at 14:08

1 Answer 1

0
\$\begingroup\$

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;
\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .