import { _decorator, Button, Component,director,find,game,Mask,Node,Prefab,Sprite, SpriteFrame } from 'cc'; const { ccclass, property } = _decorator; @ccclass('Menu') export class Menu extends Component { //加速Buton @property(Button) btnSpeed:Button = null; @property(SpriteFrame) imgSpeed_1:SpriteFrame = null; @property(SpriteFrame) imgSpeed_2:SpriteFrame = null; //暂停Button @property(Button) btnPause:Button = null; @property(SpriteFrame) imgPause_1:SpriteFrame = null; @property(SpriteFrame) imgPause_2:SpriteFrame = null; @property(SpriteFrame) imgMenuCenter_1:SpriteFrame = null;//第几波怪物 @property(SpriteFrame) imgMenuCenter_2:SpriteFrame = null;//暂停中 //弹出框 //@property(Node) dialog:Node = null; isAccelerate:boolean = false;//是否加速 currentState:boolean = null;//当前状态 isPause:boolean = false;//是否暂停 currentPauseState:boolean = null;//当前状态 start(){ this.dialog = this.node.getChildByName("Dialog"); this.dialog.active = false; // let btnQuit = this.dialog.getChildByName("BtnQuit"); // btnQuit.on(Button.EventType.CLICK,this.onBtnQuitDialog,this) // let btnSelect = this.dialog.getChildByName("BtnSelect"); // btnSelect.on(Button.EventType.CLICK,this.onBtnSelectDialog,this); // let btnRestart = this.dialog.getChildByName("BtnRestart"); // btnRestart.on(Button.EventType.CLICK,this.onBtnRestartDialog,this); // let btnResume = this.dialog.getChildByName("BtnResume"); // btnResume.on(Button.EventType.CLICK,this.onBtnQuitDialog,this); const buttonConfigs = [ {name : "BtnResume",handler : this.onBtnQuitDialog}, {name : "BtnRestart",handler : this.onBtnRestartDialog}, {name : "BtnSelect",handler : this.onBtnSelectDialog}, {name : "BtnQuit",handler : this.onBtnQuitDialog} ] buttonConfigs.forEach(config =>{ let button = this.dialog.getChildByName(config.name); button.on(Button.EventType.CLICK,config.handler,this); }); this.currentState = this.isAccelerate; //当前状态没有加速 this.btnSpeed.getComponent(Sprite).spriteFrame = this.imgSpeed_1; this.currentPauseState = this.isPause; this.btnPause.getComponent(Sprite).spriteFrame = this.imgPause_1; this.node.getChildByName("MenuCenter_01_CN").getComponent(Sprite).spriteFrame = this.imgMenuCenter_1; } //加速 onBtnSpeed(){ let btnSpeedComponent = this.btnSpeed.getComponent(Sprite); this.isAccelerate = !this.isAccelerate;//加速 this.currentState = this.isAccelerate;//当前状态为加速 if(!this.isAccelerate){ btnSpeedComponent.spriteFrame = this.imgSpeed_1; }else{ btnSpeedComponent.spriteFrame = this.imgSpeed_2; } } //暂停游戏 onBtnPause(){ let menuCenterComponent = this.node.getChildByName("MenuCenter_01_CN").getComponent(Sprite); let btnPauseComponent = this.btnPause.getComponent(Sprite); this.isPause = !this.isPause;//暂停 this.currentPauseState = this.isPause;//当前状态为暂停 if(!this.isPause){ menuCenterComponent.spriteFrame = this.imgMenuCenter_1; btnPauseComponent.spriteFrame = this.imgPause_1; }else{ menuCenterComponent.spriteFrame = this.imgMenuCenter_2; btnPauseComponent.spriteFrame = this.imgPause_2; } } //弹出dialog onBtnMore(){ console.log("More") director.pause(); this.dialog.active = true; } //退出 恢复暂停 onBtnQuitDialog(){ console.log("quitDialog"); if(director.isPaused()){ director.resume(); return; } this.dialog.active = false; } //重新选择关卡 onBtnSelectDialog(){ director.loadScene("SelectLevel"); console.log("SelectLevel"); } //重新开始游戏 onBtnRestartDialog(){ console.log("Restart"); } update(deltaTime: number) { } }