forceUpdate methods

This commit is contained in:
2025-12-24 17:26:26 +03:00
parent cc5158eef0
commit 7f22882900

86
Tween.h
View File

@ -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; // Учитываем последний тик
} }