TiledMap 遍历对象层属性

2.x *******************************************************
void TMXIsoObjectsTest::draw()
{
    CCTMXTiledMap *map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
    CCTMXObjectGroup *group = map->objectGroupNamed("Object Group 1");

    CCArray* objects = group->getObjects();
    CCDictionary* dict;
    CCObject* pObj = NULL;
    CCARRAY_FOREACH(objects, pObj)
    {
        dict = (CCDictionary*)pObj;//dynamic_cast<CCStringToStringDictionary*>(*it);

        if(!dict)
            break;
        const char* key = "x";
        int x = ((CCString*)dict->objectForKey(key))->intValue();//dynamic_cast<NSNumber*>(dict->objectForKey("x"))->getNumber();
        key = "y";
        int y = ((CCString*)dict->objectForKey(key))->intValue();//dynamic_cast<NSNumber*>(dict->objectForKey("y"))->getNumber();
        key = "width";
        int width = ((CCString*)dict->objectForKey(key))->intValue();//dynamic_cast<NSNumber*>(dict->objectForKey("width"))->getNumber();
        key = "height";
        int height = ((CCString*)dict->objectForKey(key))->intValue();//dynamic_cast<NSNumber*>(dict->objectForKey("height"))->getNumber();
        
        glLineWidth(3);
        
        ccDrawLine( ccp(x,y), ccp(x+width,y) );
        ccDrawLine( ccp(x+width,y), ccp(x+width,y+height) );
        ccDrawLine( ccp(x+width,y+height), ccp(x,y+height) );
        ccDrawLine( ccp(x,y+height), ccp(x,y) );
        
        glLineWidth(1);
    }
}
3.x******************************************************************************
void TMXIsoObjectsTest::onDraw(const Mat4 &transform, uint32_t flags)
{
    Director* director = Director::getInstance();
    CCASSERT(nullptr != director, "Director is null when seting matrix stack");
    director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);

    auto map = (TMXTiledMap*) getChildByTag(kTagTileMap);
    auto pos = map->getPosition();
    auto group = map->getObjectGroup("Object Group 1");

    auto& objects = group->getObjects();
    for (auto& obj : objects)
    {
        ValueMap& dict = obj.asValueMap();
        float x = dict["x"].asFloat();
        float y = dict["y"].asFloat();
        float width = dict["width"].asFloat();
        float height = dict["height"].asFloat();
       
        glLineWidth(3);
       
        DrawPrimitives::drawLine( pos + Vec2(x,y), pos + Vec2(x+width,y) );
        DrawPrimitives::drawLine( pos + Vec2(x+width,y), pos + Vec2(x+width,y+height) );
        DrawPrimitives::drawLine( pos + Vec2(x+width,y+height), pos + Vec2(x,y+height) );
        DrawPrimitives::drawLine( pos + Vec2(x,y+height), pos + Vec2(x,y) );
       
        glLineWidth(1);
    }

    director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}