TMXObjectGroup contains wrong values

I’m trying to implement collision in my tilemap, and I’ve created an object layer for the collision volumes. The relevant part of my tilemap is:

<objectgroup name="Collision" width="40" height="16">
  <object x="0" y="192" width="288" height="32"/>
  <object x="288" y="160" width="64" height="32"/>
  <object x="352" y="128" width="96" height="32"/>
  <object x="416" y="160" width="32" height="96"/>
  <object x="512" y="160" width="96" height="96"/>
</objectgroup>

And I’m reading this in my code, like this:

TMXObjectGroup* collisionGroup = tileMap->getObjectGroup("Collision");
if (collisionGroup == nullptr)
{
	log("Tile map has no collision layer!");
	return false;
}
	
for (auto collisionRect : collisionGroup->getObjects())
{
	ValueMap rectMap = collisionRect.asValueMap();
	int x = rectMap["x"].asInt();
	int y = rectMap["y"].asInt();
	int w = rectMap["width"].asInt();
	int h = rectMap["height"].asInt();
		
	log("New collision volume - x:%d, y:%d, width:%d, height:%d", x, y, w, h);
}

When I run, this is the output I get:

New collision volume - x:0, y:32, width:288, height:32
New collision volume - x:288, y:64, width:64, height:32
New collision volume - x:352, y:96, width:96, height:32
New collision volume - x:416, y:0, width:32, height:96
New collision volume - x:512, y:0, width:96, height:96

So everything seems to be read correctly, except for the value for “y”, which seems pretty random. Am I doing something obviously wrong here, or is this a bug?

It’s a bit strange, but the Y coordinate starts at 0 from “bottom” of the map.
I’ll try to find the definition over on Tiled’s github and post here.

Edit: you’ll have to subtract the y value from the pixel height of the map, something like mapSize.height * tileSize.height - y

Edit2: ah, yes it’s because unlike desktop graphics rendering which renders with origin 0,0 at top left, OpenGL renders from bottom left. There’s requests to allow choosing an inverted Y coordinate in the issues, but until then you just have to know that the Y pixel positions within the TMX format are based on a top-left origin coordinate system.

Edit3:
https://github.com/bjorn/tiled/issues/249
https://github.com/bjorn/tiled/issues/610

You may also run into off-by-one issues because the object Y is based on the bottom of the object rect or some related reason:
https://github.com/bjorn/tiled/issues/91

Wow, thanks a lot for your reply! In the meantime I changed from an object-layer to a regular tile-layer, since I decided not to use the built-in physics engine after all. But thanks anyway, it’s still great to know!