如何访问嵌套的plist目录cocos2dx?

时间:2017-05-04 20:10:48

标签: c++ ios cocos2d-x

我是编程新手,我无法访问嵌套在其他目录中的目录。任何建议将不胜感激。

实施例: Nested Dir

我用来访问第一个目录的Cocos2dx代码:

__String *fileName = __String::create( "InventoryData.plist" );

__Dictionary *dictionary = __Dictionary::createWithContentsOfFile(fileName->getCString() );

我已尝试使用__Dictionary::createWithDirectory("Nested Root"),但这不起作用,因为它无法找到它。我确定有一种简单的方法可以做到这一点我似乎无法找到它。抱歉没有问题。

1 个答案:

答案 0 :(得分:1)

使用遍历字典的微CCDICT_FOREACH(__dict__, __el__)

__Dictionary *dist=__Dictionary::createWithContentsOfFile("xyz.plist");

DictElement *d=nullptr;
CCDICT_FOREACH(dist, d){

  CCLOG("%s",d->getStrKey());  // It will print all key name

  if(*d->getStrKey()==*"texture"){  //Match with particular Key(here I'm using texture)

       __Dictionary *nested=(__Dictionary*)d->getObject();  // downcast nested dictionary.

       // Now you've nested dictionary you can get value or if having nested dictionary iterate again

       CCLOG("%s",nested->valueForKey("width")->getCString());  
       CCLOG("%s",nested->valueForKey("height")->getCString());  

   }
}