/** * 标签事件接收组件 */ const EventType = { GAME_SCORE: 'game_score', //游戏得分 GAME_TARGET_SCORE: 'game_target_score', //目标得分 GAME_STAGE: 'game_stage', //游戏关卡 GAME_PROGRESS: 'game_progress', //游戏进度 GAME_STAGE_SCORE: 'game_stage_score', //关卡得分 GAME_CLEAR_COUNT: 'game_clear_count', //消除个数 GAME_CLEAR_ALL: 'game_clear_all', //全部消除 GAME_CLEAR_ONE: 'game_clear_one', //消除1个(使用流星锤时) GAME_USE_HAMMER_ITEM: 'game_use_hammer_item', //使用流星锤道具 GAME_PASS_STAGE: 'game_pass_stage', //过关 GANE_NEXT_STAGE: 'game_next_stage', //下一关 } const EventName = cc.Enum({ 0: EventType.GAME_SCORE, 1: EventType.GAME_TARGET_SCORE, 2: EventType.GAME_STAGE, 3: EventType.GAME_PROGRESS, 4: EventType.GAME_STAGE_SCORE, }); const EventNameDisplay = cc.Enum({ '游戏得分': -1, '目标分数': -1, '当前关卡': -1, '游戏进度': -1, '关卡得分': -1, }); let GameEvent = cc.Class({ extends: cc.Component, editor: { menu:'', }, properties: { eventName: { tooltip: '事件名称,当发生事件时更新文字标签\n0.游戏得分:GameMatrix发出,显示到Label\n1.目标分数:GameScene发出,显示到Label\n2.当前关卡:GameScene发出,显示到Label\n3.游戏进度:GameScene发出,显示到sprite', type: EventNameDisplay, default: 0, }, }, statics: { EventType, }, onLoad () { // this.label = this.getComponent(cc.Label); // // // this.sprite = this.getComponent(cc.Sprite); // if (this.sprite) { // this.sprite.type = cc.Sprite.Type.FILLED; // this.sprite.fillType = cc.Sprite.FillType.HORIZONTAL; // } // // if (this.label || this.sprite) { // let eventType = EventName[this.eventName]; // cc.game.on(eventType, (value) => { // this._onEventTrigger(value); // }, this); // } else { // cc.warn('节点上没有Label或Sprite组件!'); // } }, /** * 事件被触发,更新Label文字 */ _onEventTrigger(value) { if (EventName[this.eventName] === EventType.GAME_PROGRESS) { if (this.sprite) { this.sprite.fillRange = value; } } if (this.label) { this.label.string = value !== undefined ? value.toString() : ''; } }, onDestroy() { cc.game.targetOff(this); } }); module.exports = GameEvent;