【Cocos2D-X 遊戲引擎】初窺門徑(11)CCUserDefault:儲存資料
阿新 • • 發佈:2019-01-28
儲存簡單的資料用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");