let GameEvent = require('GameEvent'); var ZYGameTool = require('GameTool'); cc.Class({ extends: cc.Component, properties: { gameManger: cc.Prefab, gamePauseLayer: cc.Prefab, helpNode: cc.Prefab, gameEndLayer: cc.Prefab, gameTipLyaer:cc.Prefab, _gameManger: null, }, // LIFE-CYCLE CALLBACKS: onLoad() { this.createGameLayer(); }, start() { cc.game.on(GameEvent.EventType.GANE_PAUSE, () => { this.pauseClick(); }, this); cc.game.on(GameEvent.EventType.GANE_HELP, () => { this.helpClick(); }, this); cc.game.on(GameEvent.EventType.GANE_FAIL, () => { this.gameFaild(); }, this); cc.game.on(GameEvent.EventType.GAME_TIP, () => { this.openTip(); }, this); }, createGameLayer: function () { if (this._gameManger) { this._gameMange.removeFromParent(); this._gameMange = null } if (Module.GameManager) Module.GameManager = null; this._gameManger = cc.instantiate(this.gameManger); this._gameManger.parent = this.node; this._gameManger.setAnchorPoint(cc.v2(0.5, 0.5)); this._gameManger.setContentSize(cc.v2(0, 0)); this._gameManger.setPosition(cc.v2(0, 0)); }, //提示 openTip: function () { var gameTip = cc.instantiate(this.gameTipLyaer); // console.log("-layer.width: " , gameTip.getChildByName("layer").width); gameTip.parent = this.node; gameTip.zIndex = 1000; Module.GameTipLayer.call(function (num) { if (num > 0){ Module.GameManager.txtTip("Congratulations on getting"+num+"gold coins"); } else { Module.GameManager.txtTip("Watch video failed, no gold coins"); } }.bind(this)); }, //失败 gameFaild: function () { var gameFaildNode = cc.instantiate(this.gameEndLayer); gameFaildNode.zIndex = 100; gameFaildNode.parent = this.node; Module.GameFaildLayer.call(function (state) { console.log("state: ", state); if (state) { Module.GameManager.resurrenction(); } }.bind(this)); }, restStart: function () { this._gameManger.removeFromParent(); this._gameManger = null; this.node.runAction(cc.sequence(cc.delayTime(0.2), cc.callFunc(function () { this.createGameLayer(); }.bind(this)))); }, pauseClick: function () { var pauseLayer = cc.instantiate(this.gamePauseLayer); pauseLayer.parent = this.node; pauseLayer.zIndex = 1000; Module.GamePauseLayer.call(function (name) { gameLocalData.save(Module.GameManager); if (name === "backGameBtn") { } else if (name === "restGameBtn") { gameLocalData.clear(); this.restStart(); } else if (name === "backHomeBtn") { cc.director.loadScene("homeScene"); } }.bind(this)); }, helpClick: function () { var helpNode = cc.instantiate(this.helpNode); helpNode.parent = this.node; helpNode.zIndex = 1000; ZYGameTool.getInstance().setIntegerForKey(localDataItem.gameGuide, 0); Module.GameHelpLayer.setParam(false); }, // update (dt) {}, });