cocos2dx中的用户数据的管理
提供了專門的類:CCUserDefault用來管理,且提供了單例方法:sharedUserDefault()
1.會在默認路徑cocos2d-x-2.2.3\projects\Hello\proj.win32\Debug.win32下生成一個名為UserDefault.xml 的文件,xml文件中存儲的是用戶的數據,以鍵值對的形式存儲
2.支持的數據類型:
所有的key 皆為char *型,
value:類型為bool int float double std::string.
3.使用方法:
設置:set方法,獲取,get方法
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);
bool getBoolForKey(const char* pKey);
bool getBoolForKey(const char* pKey, bool defaultValue); //第二個參數為帶默認值的,如果要獲得的key不存在,則返回默認值
int getIntegerForKey(const char* pKey);
int getIntegerForKey(const char* pKey, int defaultValue);
float getFloatForKey(const char* pKey);
float getFloatForKey(const char* pKey, float defaultValue);
double getDoubleForKey(const char* pKey);
double getDoubleForKey(const char* pKey, double defaultValue);
std::string getStringForKey(const char* pKey);
std::string getStringForKey(const char* pKey, const std::string &defaultvalue);
4.寫入磁盤:
CCUserDefault::sharedUserDefault()->flush();//刷新到磁盤,上面設置的key-value在內存,只有刷新才會到硬盤中去
?5.與xml文件相關的操作:
獲取xml文件的路徑:
CCString path=CCUserDefault::sharedUserDefault()->getXMLFilePath();//獲取xml文件的路徑
?CCLog("xmlfile path is %s", path.getCString());
判斷xml文件是否存在
CCLog("xmlfile exist is %d", CCUserDefault::sharedUserDefault()->isXMLFileExist());
?
轉載于:https://www.cnblogs.com/ttss/p/4096957.html
總結
以上是生活随笔為你收集整理的cocos2dx中的用户数据的管理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HDU 5044 Tree 树链剖分
- 下一篇: Jmeter 创建一个web测试计划