GameEvent.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * 标签事件接收组件
  3. */
  4. const EventType = {
  5. GAME_SCORE: 'game_score', //游戏得分
  6. GAME_TARGET_SCORE: 'game_target_score', //目标得分
  7. GAME_STAGE: 'game_stage', //游戏关卡
  8. GAME_PROGRESS: 'game_progress', //游戏进度
  9. GAME_STAGE_SCORE: 'game_stage_score', //关卡得分
  10. GAME_CLEAR_COUNT: 'game_clear_count', //消除个数
  11. GAME_CLEAR_ALL: 'game_clear_all', //全部消除
  12. GAME_CLEAR_ONE: 'game_clear_one', //消除1个(使用流星锤时)
  13. GAME_USE_HAMMER_ITEM: 'game_use_hammer_item', //使用流星锤道具
  14. GAME_PASS_STAGE: 'game_pass_stage', //过关
  15. GANE_NEXT_STAGE: 'game_next_stage', //下一关
  16. GANE_PAUSE: 'game_pause', //暂停
  17. GANE_HELP: 'game_help', //帮助
  18. GANE_FAIL: 'game_fail', //失败
  19. GAME_TIP: 'game_tip',//提示
  20. }
  21. const EventName = cc.Enum({
  22. 0: EventType.GAME_SCORE,
  23. 1: EventType.GAME_TARGET_SCORE,
  24. 2: EventType.GAME_STAGE,
  25. 3: EventType.GAME_PROGRESS,
  26. 4: EventType.GAME_STAGE_SCORE,
  27. });
  28. const EventNameDisplay = cc.Enum({
  29. '游戏得分': -1,
  30. '目标分数': -1,
  31. '当前关卡': -1,
  32. '游戏进度': -1,
  33. '关卡得分': -1,
  34. });
  35. let GameEvent = cc.Class({
  36. extends: cc.Component,
  37. editor: {
  38. menu:'',
  39. },
  40. properties: {
  41. eventName: {
  42. tooltip: '事件名称,当发生事件时更新文字标签\n0.游戏得分:GameMatrix发出,显示到Label\n1.目标分数:GameScene发出,显示到Label\n2.当前关卡:GameScene发出,显示到Label\n3.游戏进度:GameScene发出,显示到sprite',
  43. type: EventNameDisplay,
  44. default: 0,
  45. },
  46. },
  47. statics: {
  48. EventType,
  49. },
  50. onLoad () {
  51. // this.label = this.getComponent(cc.Label);
  52. //
  53. //
  54. // this.sprite = this.getComponent(cc.Sprite);
  55. // if (this.sprite) {
  56. // this.sprite.type = cc.Sprite.Type.FILLED;
  57. // this.sprite.fillType = cc.Sprite.FillType.HORIZONTAL;
  58. // }
  59. //
  60. // if (this.label || this.sprite) {
  61. // let eventType = EventName[this.eventName];
  62. // cc.game.on(eventType, (value) => {
  63. // this._onEventTrigger(value);
  64. // }, this);
  65. // } else {
  66. // cc.warn('节点上没有Label或Sprite组件!');
  67. // }
  68. },
  69. /**
  70. * 事件被触发,更新Label文字
  71. */
  72. _onEventTrigger(value) {
  73. if (EventName[this.eventName] === EventType.GAME_PROGRESS) {
  74. if (this.sprite) {
  75. this.sprite.fillRange = value;
  76. }
  77. } if (this.label) {
  78. this.label.string = value !== undefined ? value.toString() : '';
  79. }
  80. },
  81. onDestroy() {
  82. cc.game.targetOff(this);
  83. }
  84. });
  85. module.exports = GameEvent;