LifeBar.ts 824 B

123456789101112131415161718192021222324252627
  1. import { _decorator, Component, ProgressBar } from 'cc';
  2. import { Role, RoleState } from '../Role';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('LifeBar')
  5. export class LifeBar extends Component {
  6. _curHp: number = null;
  7. _totalHp: number = null;
  8. private _progressBar: ProgressBar = null;
  9. protected onLoad(): void {
  10. this._progressBar = this.node.getChildByName("ProgressBar").getComponent(ProgressBar);
  11. }
  12. start() {
  13. this._progressBar.progress = this._curHp / this._totalHp;
  14. }
  15. updateProgressBar(hp: number) {
  16. this._curHp = hp;
  17. this._progressBar.progress = this._curHp / this._totalHp;
  18. if (hp <= 0) {
  19. // this._role.playAnimation(RoleState.Die);
  20. this._curHp = 0;
  21. this._progressBar.progress = 0;
  22. }
  23. }
  24. }