【Cocos2D-X 遊戲引擎】初窺門徑(11)CCUserDefault:保存數據

保存簡單的數據用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




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章