当前位置 : 主页 > 手机开发 > 其它 >

CocosCreator 创建全局对象 == 同单例效果一致

来源:互联网 收集:自由互联 发布时间:2021-06-13
创建 SceneController.js cc . Class ({ extends: cc . Component , properties: { index : 999 , }, // use this for initialization onLoad: function () { }, init: function () { } // called every frame, uncomment this function to activate update
创建 SceneController.js
cc . Class ({ extends: cc . Component ,
properties: { index : 999 , },
// use this for initialization onLoad: function () {
}, init: function () {

} // called every frame, uncomment this function to activate update callback // update: function (dt) {
// }, }); 添加全局变量定义
window . SceneController = new ( require ( 'SceneController' ))()
test.js
测试 cc . log ( "======222" + SceneController . index ); SceneController . index ++ ; cc . log ( "======222" + SceneController . index );
网友评论