cocos2dx中的用户数据的管理

提供了专门的类:CCUserDefault用来管理,且提供了单例方法:sharedUserDefault()

1.会在默认路径cocos2d-x-2.2.3\projects\Hello\proj.win32\Debug.win32下生成一个名为UserDefault.xml 的文件,xml文件中存储的是用户的数据,以键值对的形式存储

2.支持的数据类型:

所有的key 皆为char *型,

value:类型为bool int float double std::string.

3.使用方法:

设置:set方法,获取,get方法

void setBoolForKey(const char* pKey, bool value);
void setIntegerForKey(const char* pKey, int value);
void setFloatForKey(const char* pKey, float value);
void setDoubleForKey(const char* pKey, double value);
void setStringForKey(const char* pKey, const std::string & value);

bool getBoolForKey(const char* pKey);
bool getBoolForKey(const char* pKey, bool defaultValue); //第二个参数为带默认值的,如果要获得的key不存在,则返回默认值
int getIntegerForKey(const char* pKey);
int getIntegerForKey(const char* pKey, int defaultValue);
float getFloatForKey(const char* pKey);
float getFloatForKey(const char* pKey, float defaultValue);
double getDoubleForKey(const char* pKey);
double getDoubleForKey(const char* pKey, double defaultValue);
std::string getStringForKey(const char* pKey);

std::string getStringForKey(const char* pKey, const std::string &defaultvalue);

4.写入磁盘:

CCUserDefault::sharedUserDefault()->flush();//刷新到磁盘,上面设置的key-value在内存,只有刷新才会到硬盘中去

 5.与xml文件相关的操作:

获取xml文件的路径:

CCString path=CCUserDefault::sharedUserDefault()->getXMLFilePath();//获取xml文件的路径

 CCLog("xmlfile path is %s", path.getCString());

判断xml文件是否存在

CCLog("xmlfile exist is %d", CCUserDefault::sharedUserDefault()->isXMLFileExist());
 

转载于:https://www.cnblogs.com/ttss/p/4096957.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值