valBar.ts 1021 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const {ccclass, property} = cc._decorator;
  2. /**
  3. * 怒气条
  4. * 血条
  5. */
  6. @ccclass
  7. export default class valBar extends cc.Component {
  8. @property(cc.Node)
  9. private tmpBar: cc.Node = null;
  10. @property(cc.Node)
  11. private barRoot: cc.Node = null;
  12. @property(cc.Label)
  13. private lbVal: cc.Label = null;
  14. // private initVal:number;
  15. @property(cc.Integer)
  16. private gap:number = 23;
  17. // LIFE-CYCLE CALLBACKS:
  18. private bars:cc.Node[]=[];
  19. onLoad () {
  20. this.tmpBar.active = false;
  21. }
  22. show(val){
  23. let sum = Math.max(val,this.bars.length);
  24. for (let i = 0; i < sum; i++) {
  25. if (this.bars.length<=i) {
  26. let newBar = cc.instantiate(this.tmpBar);
  27. newBar.parent = this.barRoot;
  28. newBar.x = i * this.gap;
  29. newBar.y = 0;
  30. this.bars[i] = newBar;
  31. }
  32. this.bars[i].active = val>i;
  33. }
  34. this.lbVal.string = val;
  35. }
  36. }