From 13e3addae42a4663d2668c0a9091ed9e55bc4e89 Mon Sep 17 00:00:00 2001 From: DashyFox Date: Wed, 6 Mar 2024 16:19:44 +0300 Subject: [PATCH] fix current --- Tween.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Tween.h b/Tween.h index 4e51b7c..273c25f 100644 --- a/Tween.h +++ b/Tween.h @@ -50,33 +50,33 @@ private: float progress; bool isPlayingF; +public: + void update() { + if (millis() - frameRateTimer > frameTime) { + dtTick(); + if (!isPlayingF || easing == nullptr) return; + if (current == to/* || progress >= duration */) { stop(); return; } + current = clamp(Tween::lerp(from, to, easing(progress / duration)), from, to); + progress = progress + Tween::dt; + frameRateTimer = millis(); + } + } + float current; + void dtTick() { uint32_t loopStartTime = millis(); dt = (loopStartTime - oldMillis) / 1000.0; oldMillis = loopStartTime; } -public: - void update() { - if (!isPlayingF || easing == nullptr) return; - if (millis() - frameRateTimer > frameTime) { - frameRateTimer = millis(); - dtTick(); - if (current == to || progress >= duration) { stop(); return; } - current = clamp(Tween::lerp(from, to, easing(progress / duration)), from, to); - progress = progress + Tween::dt; - } - } - float current; - - - void start(float from, float to, uint16_t duration, eFunc easing) { + current = from; if (from == to) { return; } this->from = from; this->to = to; this->duration = duration / 1000.0; this->easing = easing; + resetToStart(); dtTick(); isPlayingF = true;