mirror of
https://github.com/Show-maket/Tween.git
synced 2025-05-04 07:10:20 +00:00
fix current
This commit is contained in:
parent
ab421a7111
commit
13e3addae4
30
Tween.h
30
Tween.h
@ -50,33 +50,33 @@ private:
|
|||||||
float progress;
|
float progress;
|
||||||
bool isPlayingF;
|
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() {
|
void dtTick() {
|
||||||
uint32_t loopStartTime = millis();
|
uint32_t loopStartTime = millis();
|
||||||
dt = (loopStartTime - oldMillis) / 1000.0;
|
dt = (loopStartTime - oldMillis) / 1000.0;
|
||||||
oldMillis = loopStartTime;
|
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) {
|
void start(float from, float to, uint16_t duration, eFunc easing) {
|
||||||
|
current = from;
|
||||||
if (from == to) { return; }
|
if (from == to) { return; }
|
||||||
this->from = from;
|
this->from = from;
|
||||||
this->to = to;
|
this->to = to;
|
||||||
this->duration = duration / 1000.0;
|
this->duration = duration / 1000.0;
|
||||||
this->easing = easing;
|
this->easing = easing;
|
||||||
|
|
||||||
resetToStart();
|
resetToStart();
|
||||||
dtTick();
|
dtTick();
|
||||||
isPlayingF = true;
|
isPlayingF = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user