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);
- }