localstorage

1.在cocos2d-x-js 3.0中能够使用localstorage 存储keyvalue信息

var Util = cc.Class.extend({
    saveData:function(key, value) {
        cc.sys.localStorage.setItem(key, value);
    },
    getData:function(key,defaultValue) {
        if(!cc.sys.localStorage.getItem(key)) {
            if(defaultValue) {
                return defaultValue;
            }
            return -1;
        }
        return cc.sys.localStorage.getItem(key);
    }


});

Util.getInstance = function () {
    if (!this._sharedGame) {
        this._sharedGame = new Util();
        if (this._sharedGame) {
            return this._sharedGame;
        }
    } else {
        return this._sharedGame;
    }
    return null;
};

Util._sharedGame = null;
2. 能够用来存储用户配置信息。代替c++版本号的默认xml读取配置信息

posted @ 2017-06-20 10:42  cxchanpin  阅读(244)  评论(0编辑  收藏  举报