From c1d80f7a830c82d91f0b63b0d1d649e7a11d94b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E8=85=BE=E9=A3=9E?= <1067544767@qq.com> Date: Mon, 31 Mar 2025 13:45:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DLabelChange=E5=8B=BE=E9=80=89?= =?UTF-8?q?isInteger=E5=90=8E=E6=8C=81=E7=BB=AD=E6=97=B6=E9=97=B4=E4=B8=8E?= =?UTF-8?q?=E5=AE=9E=E9=99=85=E6=97=B6=E9=97=B4=E4=B8=8D=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/libs/gui/label/LabelChange.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/assets/libs/gui/label/LabelChange.ts b/assets/libs/gui/label/LabelChange.ts index d785dd5..3d39b18 100644 --- a/assets/libs/gui/label/LabelChange.ts +++ b/assets/libs/gui/label/LabelChange.ts @@ -22,6 +22,8 @@ export class LabelChange extends LabelNumber { private speed: number = 0; // 变化速度 private end: number = 0; // 最终值 + private _data: number = 0; + /** * 变化到某值,如果从当前开始的begin传入null * @param {number} duration @@ -66,6 +68,7 @@ export class LabelChange extends LabelNumber { this.callback = callback; this.speed = (end - begin) / duration; + this._data = begin; this.num = begin; this.isBegin = true; } @@ -87,25 +90,25 @@ export class LabelChange extends LabelNumber { if (this.callback) this.callback(); return; } - let num = this.num + dt * this.speed; + this._data += dt * this.speed; - if (this.isInteger){ - if(this.end < this.num) - { - num = Math.floor(num); + if (this.isInteger) { + if (this.end < this._data) { + this.num = Math.floor(this._data); } - else{ - num = Math.ceil(num); + else { + this.num = Math.ceil(this._data); } } - + else { + this.num = this._data; + } /** 变化完成 */ - if (this.isEnd(num)) { - num = this.end; + if (this.isEnd(this._data)) { + this.num = this.end; this.isBegin = false; if (this.callback) this.callback(); - } - this.num = num; + } } } } \ No newline at end of file -- Gitee