Now have a timer for animations that does ticks with deltatime...maybe it works.

This commit is contained in:
Zed A. Shaw 2026-01-27 12:52:33 -05:00
parent c0f69ed026
commit b7394f832d
5 changed files with 121 additions and 6 deletions

View file

@ -76,6 +76,38 @@ namespace animate2 {
$transform.lerp($sequence, pos, scale);
}
void Timer::start() {
clock.start();
}
void Timer::reset() {
clock.reset();
}
void Timer::restart() {
clock.restart();
}
sf::Time Timer::getElapsedTime() {
return clock.getElapsedTime();
}
void Timer::begin() {
prev_time = clock.getElapsedTime().asSeconds();
}
std::pair<int, double> Timer::commit() {
current_time = clock.getElapsedTime().asSeconds();
frame_duration = current_time - prev_time;
accumulator += frame_duration;
double tick_count = accumulator / DELTA;
double alpha = modf(tick_count, &tick_count);
accumulator -= tick_count * DELTA;
return {int(tick_count), alpha};
}
float Transform::twitching(Sequence& seq) {
float tick = 1 - std::powf(ease_rate, seq.subframe + 0.0001);
return easing(tick);