cocos2dx 玩转简单数据存储

前端之家收集整理的这篇文章主要介绍了cocos2dx 玩转简单数据存储前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

第一方法
SystemHeader.h@H_502_7@

#define SaveStringToXML CCUserDefault::sharedUserDefault()->setStringForKey

#define SaveIntegerToXML CCUserDefault::sharedUserDefault()->setIntegerForKey

#define SaveBooleanToXML CCUserDefault::sharedUserDefault()->setBoolForKey

#define LoadStringFromXML CCUserDefault::sharedUserDefault()->getStringForKey

#define LoadIntegerFromXML CCUserDefault::sharedUserDefault()->getIntegerForKey

#define LoadBooleanFromXML CCUserDefault::sharedUserDefault()->getBoolForKey

实用例子@H_502_7@

SaveStringToXML("name","dengao");
CCUserDefault::sharedUserDefault()->flush();//写了东西要提交 
std::string name = LoadStringFromXML("name");
log("name: %s ",name.c_str());

数据保存的地方@H_502_7@

log("%s",FileUtils::getInstance()->getWritablePath().c_str()); 

第二种方法@H_502_7@

CCUserDefault::sharedUserDefault()->setStringForKey("name","dengao");

std::string name = CCUserDefault::sharedUserDefault()->getStringForKey("name");
log("name: %s ",name.c_str());
原文链接:https://www.f2er.com/cocos2dx/341601.html

猜你在找的Cocos2d-x相关文章