1. 程式人生 > >Cocos2d-x Lua 訪問plist屬性列表檔案

Cocos2d-x Lua 訪問plist屬性列表檔案

C++:

    //載入plist檔案
    config = CCDictionary::createWithContentsOfFile(path);
    config->retain();
    
    //訪問其中元素
    CCArray *array =  (CCArray*)this->config->objectForKey("Name1");
    CCDictionary *item = (CCDictionary*)array->objectAtIndex(winCount);
    CCString *ret = (CCString*)item->objectForKey("Name2");

Lua:

    --載入plist檔案
    local sharedFileUtils = cc.FileUtils:getInstance()
    local fullPathForFilename = sharedFileUtils:fullPathForFilename(path)
    self.config = sharedFileUtils:getValueMapFromFile(fullPathForFilename)

    -- 訪問其中元素
    local array = self.config["Name1"]
    local item = array[winCount]
    local ret = item["Name2"]
    return ret