cocos2d-x學習筆記16:記錄存儲1:CCUserDefault
- bool getBoolForKey (const char *pKey, bool defaultValue=false)
- //Get bool value by key, if the key doesn't exist, a default value will return.
- int getIntegerForKey (const char *pKey, int defaultValue=0)
- //Get integer value by key, if the key doesn't exist, a default value will return.
- float getFloatForKey (const char *pKey, float defaultValue=0.0f)
- //Get float value by key, if the key doesn't exist, a default value will return.
- double getDoubleForKey (const char *pKey, double defaultValue=0.0)
- //Get double value by key, if the key doesn't exist, a default value will return.
- std::string getStringForKey (const char *pKey, const std::string &defaultValue="")
- //Get string value by key, if the key doesn't exist, a default value will return.
- void setBoolForKey (const char *pKey, bool value)
- //Set bool value by key.
- void setIntegerForKey (const char *pKey, int value)
- //Set integer value by key.
- void setFloatForKey (const char *pKey, float value)
- //Set float value by key.
- void setDoubleForKey (const char *pKey, double value)
- //Set double value by key.
- void setStringForKey (const char *pKey, const std::string &value)
- //Set string value by key.
- CCUserDefault *save=CCUserDefault::sharedUserDefault();
- save->setBoolForKey("bool_value",true);
- save->setDoubleForKey("double_value",0.1);
- save->setFloatForKey("float_value",0.1f);
- save->setIntegerForKey("integer_value",1);
- save->setStringForKey("string_value","test");
- if(!檔案不存在)
- {
- 使用缺省數據寫入存檔;
- }
- 讀取存檔並初始化數據;
- CCUserDefault *save=CCUserDefault::sharedUserDefault();
- if(save->getBoolForKey("isExisted"))
- {
- //相關操作
- save->setBoolForKey("isExisted",true);
- }
本文出自 “老G的小屋” 博客,請務必保留此出處http://4137613.blog.51cto.com/4127613/770754