Menu.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { _decorator, Button, Component,Sprite, SpriteFrame } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('Menu')
  4. export class Menu extends Component {
  5. //加速Buton
  6. @property(Button)
  7. btnSpeed:Button = null;
  8. @property(SpriteFrame)
  9. imgSpeed_1:SpriteFrame = null;
  10. @property(SpriteFrame)
  11. imgSpeed_2:SpriteFrame = null;
  12. //暂停Button
  13. @property(Button)
  14. btnPause:Button = null;
  15. @property(SpriteFrame)
  16. imgPause_1:SpriteFrame = null;
  17. @property(SpriteFrame)
  18. imgPause_2:SpriteFrame = null;
  19. @property(SpriteFrame)
  20. imgMenuCenter_1:SpriteFrame = null;
  21. @property(SpriteFrame)
  22. imgMenuCenter_2:SpriteFrame = null;
  23. isAccelerate:boolean = false;//是否加速
  24. currentState:boolean = null;//当前状态
  25. isPause:boolean = false;//是否暂停
  26. currentPauseState:boolean = null;//当前状态
  27. start(){
  28. this.currentState = this.isAccelerate; //当前状态没有加速
  29. this.btnSpeed.getComponent(Sprite).spriteFrame = this.imgSpeed_1;
  30. this.currentPauseState = this.isPause;
  31. this.btnPause.getComponent(Sprite).spriteFrame = this.imgPause_1;
  32. this.node.getChildByName("MenuCenter_01_CN").getComponent(Sprite).spriteFrame = this.imgMenuCenter_1;
  33. }
  34. onBtnSpeed(){
  35. this.isAccelerate = !this.isAccelerate;//加速
  36. this.currentState = this.isAccelerate;//当前状态为加速
  37. if(!this.isAccelerate){
  38. this.btnSpeed.getComponent(Sprite).spriteFrame = this.imgSpeed_1;
  39. }else{
  40. this.btnSpeed.getComponent(Sprite).spriteFrame = this.imgSpeed_2;
  41. }
  42. }
  43. onBtnPause(){
  44. this.isPause = !this.isPause;//暂停
  45. this.currentPauseState = this.isPause;//当前状态为暂停
  46. if(!this.isPause){
  47. this.node.getChildByName("MenuCenter_01_CN").getComponent(Sprite).spriteFrame = this.imgMenuCenter_1;
  48. this.btnPause.getComponent(Sprite).spriteFrame = this.imgPause_1;
  49. }else{
  50. this.node.getChildByName("MenuCenter_01_CN").getComponent(Sprite).spriteFrame = this.imgMenuCenter_2;
  51. this.btnPause.getComponent(Sprite).spriteFrame = this.imgPause_2;
  52. }
  53. }
  54. onBtnMore(){
  55. }
  56. update(deltaTime: number) {
  57. }
  58. }