ee26dc61-8211-492e-b2bc-d4b1aa0551b8.js 2.8 KB

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