setObject(string, "string element key"); auto array = Array::create(); auto dictInArray = Dictionary::create(); dictInArray->setObject(String::cr" name="description" />

Cocos2d3.0 制作PList文件

来源:未知 责任编辑:责任编辑 发表时间:2014-05-20 18:26 点击:



        auto root = Dictionary::create();
        auto string = String::create("string element value");
        root->setObject(string, "string element key");
        
        auto array = Array::create();
        
        auto dictInArray = Dictionary::create();
        dictInArray->setObject(String::create("string in dictInArray value 0"), "string in dictInArray key 0");
        dictInArray->setObject(String::create("string in dictInArray value 1"), "string in dictInArray key 1");
        array->addObject(dictInArray);
        
        array->addObject(String::create("string in array"));
        
        auto arrayInArray = Array::create();
        arrayInArray->addObject(String::create("string 0 in arrayInArray"));
        arrayInArray->addObject(String::create("string 1 in arrayInArray"));
        array->addObject(arrayInArray);
        
        root->setObject(array, "array");
        
        auto dictInDict = Dictionary::create();
        dictInDict->setObject(String::create("string in dictInDict value"), "string in dictInDict key");
        
        //add boolean to the plist
        auto booleanObject = Bool::create(true);
        dictInDict->setObject(booleanObject, "bool");
        
        //add interger to the plist
        auto intObject = Integer::create(1024);
        dictInDict->setObject(intObject, "integer");
        
        //add float to the plist
        auto floatObject = Float::create(1024.1024f);
        dictInDict->setObject(floatObject, "float");
        
        //add double to the plist
        auto doubleObject = Double::create(1024.123);
        dictInDict->setObject(doubleObject, "double");
        
        
        
        root->setObject(dictInDict, "dictInDict, Hello World");
        
        // end with /
        std::string writablePath = FileUtils::getInstance()->getWritablePath();
        std::string fullPath = writablePath + "text.plist";
        if(root->writeToFile(fullPath.c_str()))
            log("see the plist file at %s", fullPath.c_str());
        else
            log("write plist file failed");
        
      
        
        auto loadDict = __Dictionary::createWithContentsOfFile(fullPath.c_str());
        auto loadDictInDict = (__Dictionary*)loadDict->objectForKey("dictInDict, Hello World");
        auto boolValue = (__String*)loadDictInDict->objectForKey("bool");
        CCLOG("%s",boolValue->getCString());
        auto floatValue = (__String*)loadDictInDict->objectForKey("float");
        CCLOG("%s",floatValue->getCString());
        auto intValue = (__String*)loadDictInDict->objectForKey("integer");
        CCLOG("%s",intValue->getCString());
        auto doubleValue = (__String*)loadDictInDict->objectForKey("double");
        CCLOG("%s",doubleValue->getCString());


    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • cocos2d-x学习笔记(19)--label 、label atlas
    • cocos2d-x学习笔记(23)--地图的使用3--CCTMXLayer
    • Cocos2d-x学习(一):HelloWorld
    • cocos2dx在xcode下开发,编译到android上(2)
    • cocos2d 设置屏幕默认方向
    • Cocos2d-x 2.0 之 Actions “三板斧” 之一
    • cocos2d-x学习笔记(22)--地图的使用2(TMX) --Z-Order、AnchorPoi
    • cocos2d-x学习笔记(18)--游戏打包(windows平台)
    • cocos2d-x学习笔记(16)--spritesheet(精灵表单)
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1