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?