hp_bar.ts 616 B

123456789101112131415161718192021
  1. import { _decorator, Component, Node, Sprite, UITransform, Vec3 } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('hp_bar')
  4. export class hp_bar extends Component {
  5. @property(Node) point:Node = null
  6. @property(Node) hp_bar:Node = null
  7. private total:number = 100
  8. public init(){
  9. }
  10. public updateHp(hp:number){
  11. let range = (hp/this.total)
  12. this.hp_bar.getComponent(Sprite).fillRange = range
  13. let heigth = this.hp_bar.getComponent(UITransform).contentSize.height
  14. this.point.position = new Vec3(this.point.position.x,heigth*(range>1?1:range))
  15. }
  16. }