import Role from "../role/Role"; const {ccclass, property} = cc._decorator; /**战斗顶部栏 */ @ccclass export default class TopBar extends cc.Component { public myHpBar:cc.Sprite; public myEnduranceBar:cc.Sprite; public otherHpBar:cc.Sprite; public otherEnduranceBar:cc.Sprite; public timerLabel:cc.Label; public onLoad():void{ this.myHpBar = this.node.getChildByName('myHp').getChildByName('bar').getComponent(cc.Sprite); this.myEnduranceBar = this.node.getChildByName('myEndurance').getChildByName('bar').getComponent(cc.Sprite); this.otherHpBar = this.node.getChildByName('otherHp').getChildByName('bar').getComponent(cc.Sprite); this.otherEnduranceBar = this.node.getChildByName('otherEndurance').getChildByName('bar').getComponent(cc.Sprite); this.timerLabel = this.node.getChildByName('timer').getChildByName('label').getComponent(cc.Label); } public listenRole(myRole:Role,otherRole:Role):void{ myRole.node.on(Role.EventType_HpChange,(hp:number,maxHp:number)=>{ this.myHpBar.fillRange = hp/maxHp; },this); myRole.node.on(Role.EventType_EnduranceChange,(endurance:number,maxEndurance:number)=>{ this.myEnduranceBar.fillRange = endurance/maxEndurance; },this); otherRole.node.on(Role.EventType_HpChange,(hp:number,maxHp:number)=>{ this.otherHpBar.fillRange = hp/maxHp; },this); otherRole.node.on(Role.EventType_EnduranceChange,(endurance:number,maxEndurance:number)=>{ this.otherEnduranceBar.fillRange = endurance/maxEndurance; },this); } }