const weChat = require('./net/WeChat'); const DWTool = require('./utils/DWTool'); const Api = require('./net/Api'); // const Ws = require('./net/Ws'); cc.Class({ extends: cc.Component, properties: { game: cc.Node, }, // LIFE-CYCLE CALLBACKS: onLoad() { // Ws.open(); // setTimeout(() => { // Ws.emit('fuck', 111) // }, 2000) // Ws.on('getFuck', data => { // console.log(data); // }) if (!CC_WECHATGAME) { Global.showLoginPage = false; Global.channel = 'LuciferChannel'; Global.os = 1; Global.ver = 1; let uid = DWTool.getUrlParam('uid'); let token = DWTool.getUrlParam('token'); if (!uid && !token) { Global.user = { uid: 1, token: 'lucifer_test_token', nick: 'lucifer', avatar: "", gender: 1 } } else { Global.user = { uid: uid, token: token, nick: "游客", avatar: "", gender: 1 } } } else { switch (cc.sys.platform) { case cc.sys.WECHAT_GAME: Global.channel = 'weixin'; break; case cc.sys.QQ_PLAY: Global.channel = 'qq'; break; } } this.game.active = true; if (CC_WECHATGAME) { cc.game.setFrameRate(40); // 微信环境下强制游戏改为40帧的方法 window.wx.postMessage({ //初始化的时候关闭子域刷新 messageType: 8, }); } console.log("Global: " + Global.channel); this.onUpdateGame(); }, start() { }, onUpdateGame() { if (CC_WECHATGAME) { const updateManager = wx.getUpdateManager(); updateManager.onCheckForUpdate(function (res) { // 请求完新版本信息的回调 console.log(res.hasUpdate) }) updateManager.onUpdateReady(function () { wx.showModal({ title: '更新提示', content: '新版本已经准备好,是否重启应用?', success: function (res) { if (res.confirm) { // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 updateManager.applyUpdate() } } }) }) updateManager.onUpdateFailed(function () { // 新的版本下载失败 }) } } // update (dt) {}, });