保存简单的数据用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");
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索cocos2d-x
, const
, char
, value
, defaultvalue
, 数值
, 浮点
CCUserDefault类
,以便于您获取更多的相关知识。
时间: 2024-05-16 00:26:19