8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

cocos2d-xでplistファイルを読み込む方法

Posted at

忘れちゃうので自分メモ

★用意するファイルの中身
<?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()

8
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?