Cocos2d3.0 制作PList文件
2014-05-02 20:52
357 查看
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());
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());
相关文章推荐
- Cocos2d3.0 制作PList文件
- 【Cocos2d-x 3.0学习笔记】coco2d-s 读取plist 文件报错
- 【iOS-Cocos2d游戏开发】使用plist文件制作简单精灵
- iOS-Cocos2d游戏开发】使用plist文件制作简单精灵
- cocos2d plist文件使用(在一张大图中放置多个精灵图片)
- cocos2d-x plist文件各个属性的含义
- Cocos2d-3.x_读取plist文件
- Cocos2d-x 3.0 开发(十一)3.0 alpha1文件结构变化
- cocos2d 加载 plist文件(帧动画)
- cocos2d-x 内存优化之prv.ccz plist 文件加载
- Cocos2d-x 3.0 开发(十五)使用UILayout布局,制作对话界面
- 实习小白::(转) Cocos2d-x 3.0开发(五)关联程序逻辑与cocoStudio导出文件
- 如何使用Cocos2d-x 3.0制作基于tilemap的游戏:第三部分(完)
- Cocos2d-x 3.0 开发(十六)cocos2dx-3.0beta版建立新项目并加载CocoStudio导出文件
- cocos2d-x 读取配置文件plist
- Cocos2d-x 3.10 使用BMFont 制作自定义位图字体.fnt文件
- 让quick-cocos2d-x支持加密的plist文件
- cocos2d pList文件
- cocos2d plist 文件
- cocos2d-x 2.1 -- 读取.plist文件