• cocos2dx中的用户数据的管理


    提供了专门的类:CCUserDefault用来管理,且提供了单例方法:sharedUserDefault()

    1.会在默认路径cocos2d-x-2.2.3projectsHelloproj.win32Debug.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());
     

  • 相关阅读:
    数据库分区、分表、分库、分片
    C# 创建Windows Service(Windows服务)程序
    C# 自定义控件容器,设计时可添加控件
    redis配置文件中常用配置详解
    将博客搬至CSDN
    MD5加密之加密字符串
    MD5加密之提取文件的MD5特征码
    安卓手机下拉状态栏的代码实现
    Android中四大组件总结
    Android中内容提供者ContentProvider的详解
  • 原文地址:https://www.cnblogs.com/ttss/p/4096957.html
Copyright © 2020-2023  润新知