【Cocos2D-X 游戏引擎】初窥门径(11)CCUserDefault:保存数据

来源:互联网 发布:arm 是什么软件 编辑:程序博客网 时间:2024/04/29 18:34

保存简单的数据用CCUserDefault和Android中的SharedPreferences一样,都是以键值对存储的。


//获取bool型值 bool getBoolForKey(const char* pKey, bool defaultValue = false); //获取整型值 int  getIntegerForKey(const char* pKey, int defaultValue = 0);//获取浮点数值 float getFloatForKey(const char* pKey, float defaultValue=0.0f); //获取双精度浮点数值 double  getDoubleForKey(const char* pKey, double defaultValue=0.0);//获取字符串 std::string getStringForKey(const char* pKey, const std::string & defaultValue = "");  //设置布尔型值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);


用法:

CCUserDefault::sharedUserDefault()->setStringForKey("UserName","henn");




转载请注明出处:http://blog.csdn.net/Vestigge




原创粉丝点击