mirror of
https://github.com/Show-maket/Tween.git
synced 2025-06-27 20:59:36 +00:00
fix last play tick
This commit is contained in:
17
Tween.h
17
Tween.h
@ -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;
|
||||
|
Reference in New Issue
Block a user