Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

1 Answer 1

up vote 0 down vote accepted

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;
share|improve this answer
    
Mark your answer as accepted if you solved the problem. –  Sean Middleditch Feb 11 '13 at 19:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.