12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- const {ccclass, property} = cc._decorator;
- /**
- * 怒气条
- * 血条
- */
- @ccclass
- export default class valBar extends cc.Component {
- @property(cc.Node)
- private tmpBar: cc.Node = null;
- @property(cc.Node)
- private barRoot: cc.Node = null;
- @property(cc.Label)
- private lbVal: cc.Label = null;
- // private initVal:number;
- @property(cc.Integer)
- private gap:number = 23;
- // LIFE-CYCLE CALLBACKS:
- private bars:cc.Node[]=[];
- onLoad () {
- this.tmpBar.active = false;
- }
-
- show(val){
- let sum = Math.max(val,this.bars.length);
- for (let i = 0; i < sum; i++) {
- if (this.bars.length<=i) {
- let newBar = cc.instantiate(this.tmpBar);
- newBar.parent = this.barRoot;
- newBar.x = i * this.gap;
- newBar.y = 0;
- this.bars[i] = newBar;
- }
-
-
- this.bars[i].active = val>i;
- }
- this.lbVal.string = val;
- }
- }
|