fix current

This commit is contained in:
DashyFox 2024-03-06 16:19:44 +03:00
parent ab421a7111
commit 13e3addae4

30
Tween.h
View File

@ -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;