如何用cocos2d-x v3.2读取plist级别

时间:2014-11-05 15:40:49

标签: cocos2d-x plist cocos2d-x-3.0

我有这个plist文件:

    <?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">
<key>levels</key>
<array>
    <dict>
        <key>x</key>
        <int>80</int>
        <key>y</key>
        <int>266</int>
    </dict>
    <dict>
        <key>x</key>
        <int>170</int>
        <key>y</key>
        <int>266</int>
    </dict>
</array>
</plist>

我试图用cocos2dx v3.2读取这个文件:

ValueMap data;
std::string path = FileUtils::getInstance()->fullPathForFilename("my.plist");
data = FileUtils::getInstance()->getValueMapFromFile(path);
auto arrLevels = data.at("levels").asValueVector();
for(int i = 0; i < arrLevels.capacity(); i++){
//I don't know what I have to do here to get the x value and y value of the current item.
}
有人可以帮帮我吗?我在所有互联网上搜索,我发现的所有例子都不足。

1 个答案:

答案 0 :(得分:4)

使用此功能;

ValueMap data;
std::string path = FileUtils::getInstance()->fullPathForFilename("my.plist");
data = FileUtils::getInstance()->getValueMapFromFile(path);

auto arrLevels = data.at("levels").asValueVector();

for (int i = 0; i<arrLevels.size(); i++) {
     ValueMap sdata = (arrLevels[i]).asValueMap();

     int x =  sData["x"].asInt();
     int y =  sData["y"].asInt();
    }