|
|
@@ -2,49 +2,17 @@ const { ccclass, property } = cc._decorator;
|
|
|
|
|
|
@ccclass
|
|
|
export default class ProgressBar extends cc.Component {
|
|
|
- @property({ type: cc.Sprite, displayName: '进度条背景' })
|
|
|
- blood_1: cc.Sprite = null;
|
|
|
+ @property({ type: cc.Sprite, displayName: '进度条' })
|
|
|
+ bar: cc.Sprite = null;
|
|
|
|
|
|
- @property({ type: cc.Sprite, displayName: '进度条动画节点' })
|
|
|
- blood_2: cc.Sprite = null;
|
|
|
-
|
|
|
- @property(cc.Label)
|
|
|
- lbl_progress: cc.Label = null;
|
|
|
-
|
|
|
- private maxlen: number;
|
|
|
- private current: number;
|
|
|
- private max: number;
|
|
|
- private tweenSpeed: number = 100;
|
|
|
+ private len: number;
|
|
|
|
|
|
onLoad() {
|
|
|
- this.maxlen = this.blood_1.node.width;
|
|
|
- }
|
|
|
-
|
|
|
- init(current, max) {
|
|
|
- this.current = current;
|
|
|
- this.max = max;
|
|
|
- this.blood_2.node.width = this.maxlen;
|
|
|
- this.updateLabel();
|
|
|
- }
|
|
|
-
|
|
|
- setProgress(current, tween: boolean = false) {
|
|
|
- let dis = (this.current - current) * this.maxlen / this.max;
|
|
|
- this.current = current;
|
|
|
- let w = current / this.max * this.maxlen;
|
|
|
- if (tween) {
|
|
|
- let t = dis / this.tweenSpeed;
|
|
|
- cc.tween(this.blood_2.node).to(t, { width: w }).start();
|
|
|
- }
|
|
|
- else {
|
|
|
- this.blood_2.node.width = w;
|
|
|
- }
|
|
|
-
|
|
|
- this.updateLabel();
|
|
|
+ this.len = this.bar.node.width;
|
|
|
+ this.bar.node.x = -this.len;
|
|
|
}
|
|
|
|
|
|
- updateLabel() {
|
|
|
- if (this.lbl_progress) {
|
|
|
- this.lbl_progress.string = Math.floor(this.current) + "/" + Math.floor(this.max);
|
|
|
- }
|
|
|
+ setProgress(current) {
|
|
|
+ this.bar.node.x = -this.len + (current / 100 * this.len);
|
|
|
}
|
|
|
}
|