fix last play tick

This commit is contained in:
2025-05-06 13:58:21 +03:00
parent 1fda2daaec
commit 663b10f898

17
Tween.h
View File

@ -42,6 +42,7 @@ private:
EasingFunc::eFunc easing = nullptr;
float progress;
bool isPlayingF;
bool isLastPlay;
public:
float current;
@ -56,13 +57,24 @@ public:
if (millis() - frameRateTimer > frameTime) {
dtTick();
if (!isPlayingF || easing == nullptr) return;
if (((uint16_t)current) == ((uint16_t)to) /* || progress > duration */) { stop(); return; }
if(!isLastPlay){
if (/* ((uint16_t)current) == ((uint16_t)to) || */ progress > duration) {
current = to;
isLastPlay = true;
return;
}
current = clamp(Tween::lerp(from, to, easing(progress / duration)), from, to);
progress = progress + Tween::dt;
} else {
stop();
}
frameRateTimer = millis();
}
}
float getProgress() {
return clamp(progress / duration, 0, 1);
}
void start(float from, float to, uint16_t duration, EasingFunc::eFunc easing) {
current = from;
@ -82,6 +94,7 @@ public:
}
void stop() {
isPlayingF = false;
isLastPlay = false;
}
bool isPlaying() const {
@ -109,11 +122,11 @@ public:
return sum / (steps + 1); // Среднее значение функции
}
private:
static float lerp(float a, float b, float t) {
return a + (b - a) * t;
}
private:
int clamp(int value, int a, int b) {
if (a > b) {
a ^= b;