1. js 全局共享类 单例模式
var Util = cc.Class.extend({
init:function() {
return true;
}
});
Util.getInstance = function () {
cc.assert(this._sharedGame, "Havn't call setSharedGame");
if (!this._sharedGame) {
this._sharedGame = new Util();
if (this._sharedGame.init()) {
return this._sharedGame;
}
} else {
return this._sharedGame;
}
return null;
};
Util._sharedGame = null;
2. 全局共享变量
var BG = BG || {};
BG.PIC_RESOURCE = {
size:cc.s(800, 480),
directory:"pic"
};
BG.SOUND_RESOURCE = {
directory:"sound"
};
BG.DESIGN_RESOLUTION_SIZE = cc.s(800, 480);