忘れちゃうので自分メモ
★用意するファイルの中身
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AllItems
<dict>
<key>CryOfCharacter01
<string>Character01.caf
<key>CryOfCharacter02
<string>Character02.caf
<key>CryOfCharacter03
<string>Character03.caf
</dict>
</dict>
</plist>
★読み出し処理
void MyClass::readPropertyList() {
CCLOG("start readPropertyList()");
// plistを読み込む
cocos2d::CCDictionary *plistDic = cocos2d::CCDictionary::createWithContentsOfFile("ItemList.plist");
cocos2d::CCDictionary *Items = (cocos2d::CCDictionary*)plistDic->objectForKey("AllItems");
cocos2d::CCArray *keys = (cocos2d::CCArray*)Items->allKeys();
CCLOG("keys count[%d]", keys->count());
for(int i=0; i < keys->count(); i++) {
// キー値を取得
cocos2d::CCObject *lists= keys->objectAtIndex(i);
const char * key = ((cocos2d::CCString*)(lists))->getCString();
// 値を取得
cocos2d::CCObject* itemName = Items->objectForKey(key);
CCLOG("No.%02d: KEY[%s] VALUE[%s]", i + 1, key, ((cocos2d::CCString *)(itemName))->getCString());
}
CCLOG("end readPropertyList()");
}
★実行結果
Cocos2d: start readPropertyList()
Cocos2d: keys count[3]
Cocos2d: No.01: KEY[CryOfCharacter01] VALUE[Character01.caf]
Cocos2d: No.02: KEY[CryOfCharacter03] VALUE[Character03.caf]
Cocos2d: No.03: KEY[CryOfCharacter02] VALUE[Character02.caf]
Cocos2d: end readPropertyList()