日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

cocos2dx中的用户数据的管理

發布時間:2025/7/25 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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中的用户数据的管理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。