| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 | import { _decorator, Button, Component,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;    isAccelerate:boolean = false;//是否加速    currentState:boolean = null;//当前状态    isPause:boolean = false;//是否暂停    currentPauseState:boolean = null;//当前状态    start(){        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(){        this.isAccelerate = !this.isAccelerate;//加速        this.currentState = this.isAccelerate;//当前状态为加速        if(!this.isAccelerate){            this.btnSpeed.getComponent(Sprite).spriteFrame  = this.imgSpeed_1;        }else{            this.btnSpeed.getComponent(Sprite).spriteFrame  = this.imgSpeed_2;        }    }    onBtnPause(){        this.isPause = !this.isPause;//暂停        this.currentPauseState = this.isPause;//当前状态为暂停        if(!this.isPause){            this.node.getChildByName("MenuCenter_01_CN").getComponent(Sprite).spriteFrame = this.imgMenuCenter_1;            this.btnPause.getComponent(Sprite).spriteFrame  = this.imgPause_1;        }else{            this.node.getChildByName("MenuCenter_01_CN").getComponent(Sprite).spriteFrame = this.imgMenuCenter_2;            this.btnPause.getComponent(Sprite).spriteFrame  = this.imgPause_2;        }    }    onBtnMore(){            }    update(deltaTime: number) {            }}
 |