GameEvent.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. }
  17. const EventName = cc.Enum({
  18. 0: EventType.GAME_SCORE,
  19. 1: EventType.GAME_TARGET_SCORE,
  20. 2: EventType.GAME_STAGE,
  21. 3: EventType.GAME_PROGRESS,
  22. 4: EventType.GAME_STAGE_SCORE,
  23. });
  24. const EventNameDisplay = cc.Enum({
  25. '游戏得分': -1,
  26. '目标分数': -1,
  27. '当前关卡': -1,
  28. '游戏进度': -1,
  29. '关卡得分': -1,
  30. });
  31. let GameEvent = cc.Class({
  32. extends: cc.Component,
  33. editor: {
  34. menu:'',
  35. },
  36. properties: {
  37. eventName: {
  38. tooltip: '事件名称,当发生事件时更新文字标签\n0.游戏得分:GameMatrix发出,显示到Label\n1.目标分数:GameScene发出,显示到Label\n2.当前关卡:GameScene发出,显示到Label\n3.游戏进度:GameScene发出,显示到sprite',
  39. type: EventNameDisplay,
  40. default: 0,
  41. },
  42. },
  43. statics: {
  44. EventType,
  45. },
  46. onLoad () {
  47. // this.label = this.getComponent(cc.Label);
  48. //
  49. //
  50. // this.sprite = this.getComponent(cc.Sprite);
  51. // if (this.sprite) {
  52. // this.sprite.type = cc.Sprite.Type.FILLED;
  53. // this.sprite.fillType = cc.Sprite.FillType.HORIZONTAL;
  54. // }
  55. //
  56. // if (this.label || this.sprite) {
  57. // let eventType = EventName[this.eventName];
  58. // cc.game.on(eventType, (value) => {
  59. // this._onEventTrigger(value);
  60. // }, this);
  61. // } else {
  62. // cc.warn('节点上没有Label或Sprite组件!');
  63. // }
  64. },
  65. /**
  66. * 事件被触发,更新Label文字
  67. */
  68. _onEventTrigger(value) {
  69. if (EventName[this.eventName] === EventType.GAME_PROGRESS) {
  70. if (this.sprite) {
  71. this.sprite.fillRange = value;
  72. }
  73. } if (this.label) {
  74. this.label.string = value !== undefined ? value.toString() : '';
  75. }
  76. },
  77. onDestroy() {
  78. cc.game.targetOff(this);
  79. }
  80. });
  81. module.exports = GameEvent;