/** * 游戏内暂停 */ import GamePlay from "../GamePlay"; const { ccclass, property } = cc._decorator; @ccclass export default class PauseUI extends cc.Component { @property(cc.Node) node_bg: cc.Node = null; @property(cc.Node) node_closeBtn: cc.Node = null; @property(cc.Node) node_musicSwitch: cc.Node = null; @property(cc.Node) node_music_on: cc.Node = null; @property(cc.Node) node_music_off: cc.Node = null; @property(cc.Node) node_effectSwitch: cc.Node = null; @property(cc.Node) node_effect_on: cc.Node = null; @property(cc.Node) node_effect_off: cc.Node = null; @property(cc.Node) node_restartBtn: cc.Node = null; @property(cc.Node) node_exitBtn: cc.Node = null; start() { mk.ad.showNative(4); this.node_bg.setContentSize(cc.winSize.width, cc.winSize.height); this.initEvent(); } onEnable() { this.initMsuicSwitchState(); this.initEffectSwitchState(); } //初始化 initMsuicSwitchState() { this.node_music_on.active = mk.audio.getSwitchMusic(); this.node_music_off.active = !this.node_music_on.active } initEffectSwitchState() { this.node_effect_on.active = mk.audio.getSwitchEffect(); this.node_effect_off.active = !this.node_effect_on.active; } initEvent() { this.node_closeBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this); this.node_musicSwitch.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this); this.node_effectSwitch.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this); this.node_restartBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this); this.node_exitBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this); } onClickBtn(event: cc.Event.EventTouch) { mk.audio.playEffect("button"); switch (event.currentTarget) { case this.node_closeBtn: this.onClickClose(); break; case this.node_musicSwitch: this.onClickMusicSwitch(); break; case this.node_effectSwitch: this.onClickEffectSwitch(); break; case this.node_exitBtn: this.onClickExitBtn(); break; case this.node_restartBtn: this.onClickRestartBtn(); break; } } onClickClose() { console.log("点击关闭按钮", this.node.name); mk.ui.closePanel(this.node.name); mk.ad.destroyNativeAd(); } onClickMusicSwitch() { mk.audio.switchMusicFunc(); this.initMsuicSwitchState(); } onClickEffectSwitch() { mk.audio.switchEffectFunc(); this.initEffectSwitchState(); } onClickRestartBtn() { GamePlay.Inst.restart(); mk.ui.closePanel(this.node.name); mk.ad.destroyNativeAd(); } onClickExitBtn() { mk.ui.closePanel("PauseUI") GamePlay.Inst.restart();//退出不扣体力 GamePlay.Inst.node.active = false; mk.ad.destroyNativeAd(); } }