TopBar.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import Role from "../role/Role";
  2. const {ccclass, property} = cc._decorator;
  3. /**战斗顶部栏 */
  4. @ccclass
  5. export default class TopBar extends cc.Component {
  6. public myHpBar:cc.Sprite;
  7. public myEnduranceBar:cc.Sprite;
  8. public otherHpBar:cc.Sprite;
  9. public otherEnduranceBar:cc.Sprite;
  10. public timerLabel:cc.Label;
  11. public onLoad():void{
  12. this.myHpBar = this.node.getChildByName('myHp').getChildByName('bar').getComponent(cc.Sprite);
  13. this.myEnduranceBar = this.node.getChildByName('myEndurance').getChildByName('bar').getComponent(cc.Sprite);
  14. this.otherHpBar = this.node.getChildByName('otherHp').getChildByName('bar').getComponent(cc.Sprite);
  15. this.otherEnduranceBar = this.node.getChildByName('otherEndurance').getChildByName('bar').getComponent(cc.Sprite);
  16. this.timerLabel = this.node.getChildByName('timer').getChildByName('label').getComponent(cc.Label);
  17. }
  18. public listenRole(myRole:Role,otherRole:Role):void{
  19. myRole.node.on(Role.EventType_HpChange,(hp:number,maxHp:number)=>{
  20. this.myHpBar.fillRange = hp/maxHp;
  21. },this);
  22. myRole.node.on(Role.EventType_EnduranceChange,(endurance:number,maxEndurance:number)=>{
  23. this.myEnduranceBar.fillRange = endurance/maxEndurance;
  24. },this);
  25. otherRole.node.on(Role.EventType_HpChange,(hp:number,maxHp:number)=>{
  26. this.otherHpBar.fillRange = hp/maxHp;
  27. },this);
  28. otherRole.node.on(Role.EventType_EnduranceChange,(endurance:number,maxEndurance:number)=>{
  29. this.otherEnduranceBar.fillRange = endurance/maxEndurance;
  30. },this);
  31. }
  32. }