Hi,
Been playing with CCTMXTiledMap and seem to have encountered a bug in CCTMXObjectGroup
parsing.
Using latest stable cocosdx 2.1.1 and Tiled Map Editor 0.9.0
For example, with following TMX data:
The returned Y axis value is always incorrect, at exception of first object.
Object x=32 y=160 width=32 height=160
Object x=384 y=352 width=448 height=32
Object x=800 y=384 width=32 height=96
Object x=384 y=64 width=224 height=32
Object x=800 y=160 width=160 height=32
Object x=928 y=0 width=32 height=160
Object x=64 y=160 width=192 height=32
Object x=256 y=192 width= height=
Object x=608 y=96 width= height=
Object x=64 y=288 width= height=
I’m parsing the object group like following, please comment if you spot something wrong in the code:
// Load tilemap
this->pMap = CCTMXTiledMap::create("maps/level1.tmx");
this->addChild(this->pMap, -1);
// Iterate object groups
CCObject *groups;
CCARRAY_FOREACH(this->pMap->getObjectGroups(), groups)
{
// object groups (object layers)
CCTMXObjectGroup *group = dynamic_cast(groups);
if(group != NULL)
{
// Found collision group
if(strcmp("Collision", group->getGroupName()) == 0)
{
// Iterate objects
CCObject *items;
CCARRAY_FOREACH(group->getObjects(), items)
{
CCDictionary * object = dynamic_cast(items);
if(object != NULL)
{
// Get values
CCString* x = (CCString *)object->valueForKey("x");
CCString* y = (CCString *)object->valueForKey("y");
CCString* width = (CCString *)object->valueForKey("width");
CCString* height = (CCString *)object->valueForKey("height");
CCLog("Object x=%s y=%s width=%s height=%s", x->getCString(), y->getCString(), width->getCString(), height->getCString());
}
}
}
}
}
I’ll have a look into CCTMXXMLParser source as well and will post if find something wrong with it.
level1.tmx.zip (0.9 KB)
SceneTileMapBox2D.h.zip (0.6 KB)
SceneTileMapBox2D.cpp.zip (2.6 KB)