mirror of
https://github.com/Show-maket/Tween.git
synced 2026-02-21 11:14:45 +00:00
forceUpdate methods
This commit is contained in:
86
Tween.h
86
Tween.h
@ -184,6 +184,92 @@ public:
|
|||||||
triggerLastTick = false;
|
triggerLastTick = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// =========================================================
|
||||||
|
// Force Update API - принудительное обновление параметров
|
||||||
|
// =========================================================
|
||||||
|
|
||||||
|
// Принудительное обновление начальной точки (from) без сброса прогресса
|
||||||
|
// Пересчитывает current на основе нового from и текущего прогресса
|
||||||
|
void forceUpdateFrom(float newFrom) {
|
||||||
|
from = newFrom;
|
||||||
|
if (isPlayingF && duration > 0.0f) {
|
||||||
|
// Пересчитываем current на основе нового from и текущего прогресса
|
||||||
|
float normProgress = constrain(progress / duration, 0, 1);
|
||||||
|
if (easingFunc) {
|
||||||
|
current = Tween::lerp(from, to, easingFunc(normProgress));
|
||||||
|
} else if (easing) {
|
||||||
|
current = Tween::lerp(from, to, easing(normProgress));
|
||||||
|
} else {
|
||||||
|
current = Tween::lerp(from, to, normProgress);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Если не играет или duration = 0, просто обновляем from
|
||||||
|
current = from;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Принудительное обновление конечной точки (to) без сброса прогресса
|
||||||
|
// Пересчитывает current на основе нового to и текущего прогресса
|
||||||
|
void forceUpdateTo(float newTo) {
|
||||||
|
to = newTo;
|
||||||
|
if (isPlayingF && duration > 0.0f) {
|
||||||
|
// Пересчитываем current на основе нового to и текущего прогресса
|
||||||
|
float normProgress = constrain(progress / duration, 0, 1);
|
||||||
|
if (easingFunc) {
|
||||||
|
current = Tween::lerp(from, to, easingFunc(normProgress));
|
||||||
|
} else if (easing) {
|
||||||
|
current = Tween::lerp(from, to, easing(normProgress));
|
||||||
|
} else {
|
||||||
|
current = Tween::lerp(from, to, normProgress);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Если не играет или duration = 0, просто обновляем to и current
|
||||||
|
current = to;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Принудительное обновление обеих точек (from и to) без сброса прогресса
|
||||||
|
// Пересчитывает current на основе новых точек и текущего прогресса
|
||||||
|
void forceUpdateFromTo(float newFrom, float newTo) {
|
||||||
|
from = newFrom;
|
||||||
|
to = newTo;
|
||||||
|
if (isPlayingF && duration > 0.0f) {
|
||||||
|
// Пересчитываем current на основе новых точек и текущего прогресса
|
||||||
|
float normProgress = constrain(progress / duration, 0, 1);
|
||||||
|
if (easingFunc) {
|
||||||
|
current = Tween::lerp(from, to, easingFunc(normProgress));
|
||||||
|
} else if (easing) {
|
||||||
|
current = Tween::lerp(from, to, easing(normProgress));
|
||||||
|
} else {
|
||||||
|
current = Tween::lerp(from, to, normProgress);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Если не играет или duration = 0, устанавливаем current в from
|
||||||
|
current = from;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Принудительное обновление прогресса (progress) без сброса других параметров
|
||||||
|
// Пересчитывает current на основе нового прогресса
|
||||||
|
// newProgress - абсолютное значение прогресса (0..duration)
|
||||||
|
void forceUpdateProgress(float newProgress) {
|
||||||
|
progress = constrain(newProgress, 0, duration);
|
||||||
|
if (duration > 0.0f) {
|
||||||
|
// Пересчитываем current на основе нового прогресса
|
||||||
|
float normProgress = constrain(progress / duration, 0, 1);
|
||||||
|
if (easingFunc) {
|
||||||
|
current = Tween::lerp(from, to, easingFunc(normProgress));
|
||||||
|
} else if (easing) {
|
||||||
|
current = Tween::lerp(from, to, easing(normProgress));
|
||||||
|
} else {
|
||||||
|
current = Tween::lerp(from, to, normProgress);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Если duration = 0, устанавливаем current в to
|
||||||
|
current = to;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool isPlaying() const {
|
bool isPlaying() const {
|
||||||
return isPlayingF || triggerLastTick; // Учитываем последний тик
|
return isPlayingF || triggerLastTick; // Учитываем последний тик
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user