From 451b27982bd5910dbe4620c99fddb320f0261d97 Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Mon, 10 Dec 2018 18:40:09 -0800 Subject: [PATCH] text counter emit even already reached value --- src/components/text-counter.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/text-counter.js b/src/components/text-counter.js index 358b387..19ed0a6 100644 --- a/src/components/text-counter.js +++ b/src/components/text-counter.js @@ -16,6 +16,7 @@ AFRAME.registerComponent('text-counter', { init: function () { this.currentValue = 0; + this.hasCompleted = false; this.textValue = {value : ''}; }, @@ -23,16 +24,18 @@ AFRAME.registerComponent('text-counter', { this.currentValue = 0; this.textValue.value = `${this.data.prefix}${this.decimals(0)}${this.data.suffix}`; this.el.setAttribute('text', this.textValue); + this.hasCompleted = false; }, tick: function (time, timeDelta) { - if (!this.data.enabled || this.currentValue >= this.data.value) { return; } + if (!this.data.enabled || this.hasCompleted) { return; } this.currentValue += this.data.value * (timeDelta / this.data.dur); if (this.currentValue >= this.data.value) { this.currentValue = this.data.value; if (this.data.emit) { this.el.emit('textcounterdone', null, false); } + this.hasCompleted = true; } this.textValue.value =