2017-05-04 62 views
0

編程新手,我無法訪問嵌套在其他目錄內的目錄。任何建議,將不勝感激。如何訪問嵌套的plist目錄cocos2dx?

例子: 與Cocos2dx Nested Dir

代碼,我用它來訪問的第一個目錄:

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

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

我一直在使用__Dictionary::createWithDirectory("Nested Root")試過,但還是不行,因爲它不能找到它。我確定有一個簡單的方法來做到這一點,我似乎無法找到它。對不起noob問題。

回答

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()); 

    } 
} 
+0

你能解釋一下*「紋理」是什麼。爲什麼我不能用字符串變量替換它。 – MinusSign

+0

「紋理」是類型爲「const char *」的字符串文字,因此我解引用以獲取指針指向的數據。紋理只是我的.plist中的一個條目,它本身就是其父代詞典中的__Dictionary * dist – Aryan

+0

當兩個條目具有相同的起始字符時,我遇到問題。他們似乎混淆了任何想法? – MinusSign