I am trying to load some objects like this:
CCTMXObjectGroup* solids = map->objectGroupNamed("Solids");
CCAssert(solids != 0, "'Solids' object group was not found.");
CCMutableArray* solidObjects = solids->getObjects();
arraySolids->removeAllObjects();
while (solidObjects->count() > 0)
{
float x = solidObjects->getLastObject()->objectForKey("x")->toFloat();
float y = solidObjects->getLastObject()->objectForKey("y")->toFloat();
float w = solidObjects->getLastObject()->objectForKey("width")->toFloat();
float h = solidObjects->getLastObject()->objectForKey("height")->toFloat();
//float x = solidObjects->getObjectAtIndex(0)->objectForKey("x")->toFloat();
//float y = solidObjects->getObjectAtIndex(0)->objectForKey("y")->toFloat();
//float w = solidObjects->getObjectAtIndex(0)->objectForKey("width")->toFloat();
//float h = solidObjects->getObjectAtIndex(0)->objectForKey("height")->toFloat();
Solid* s = new Solid();
s->setPosition(ccp(x, y));
s->width = w;
s->height = h;
arraySolids->addObject(s);
this->addChild(s);
solidObjects->removeObjectAtIndex(0);
CCLOG("Solid (%f, %f, %f, %f)", x, y, w, h);
return true;
}
The log shows: (800, 448, 64, 32)
If I get the object at the first index, instead, the log shows: (0, 288, 96, 32)
This is what my object group looks like:
The y coordinates are messed up. Can anyone explain why that is?
edit:
Nevermind, The coordinates are different because the parser takes into account that the cocos2d axis is different to the one used in Tiled Map editor.
That leads me to another question. The log shows that the first object’s properties are: (0, 288, 96, 32)
How does it convert between Tiled coordinate space to cocos2d coordinate space? 768-448 = 320. Shouldn’t the y coordinate be 320 and not 288?