Animation motion() almost works but need to tweak the calculations so they go for the length of the animation?

This commit is contained in:
Zed A. Shaw 2026-01-21 23:53:13 -05:00
parent 60c405b1fc
commit 31b815d43e
3 changed files with 23 additions and 17 deletions

View file

@ -21,6 +21,7 @@ namespace animate2 {
void Animate2::play() {
dbc::check(!playing, "can't call play while playing?");
$sequence.current = 0;
$sequence.subframe = 0.0f;
$sequence.loop_count = 0;
playing = true;
$sequence.timer.start();
@ -65,6 +66,7 @@ namespace animate2 {
}
void Animate2::update() {
$sequence.subframe += $transform.speed;
update_frame();
}
@ -74,15 +76,13 @@ namespace animate2 {
}
float Transform::twitching(Sequence& seq) {
float subframe = seq.timer.getElapsedTime().asSeconds();
float tick = 1 - std::powf(ease_rate, subframe + 0.0001);
fmt::println("TICK {}; subframe: {}", tick, subframe);
float tick = 1 - std::powf(ease_rate, seq.subframe + 0.0001);
switch(easing) {
case ease::NONE:
return 0.0;
case ease::SINE:
return std::abs(std::sin(subframe * ease_rate));
return std::abs(std::sin(seq.subframe * ease_rate));
case ease::OUT_CIRC:
return ease::out_circ(tick);
case ease::OUT_BOUNCE:
@ -102,7 +102,7 @@ namespace animate2 {
}
}
void Transform::lerp(Sequence& seq, sf::Vector2f& scale_out, sf::Vector2f& pos_out) {
void Transform::lerp(Sequence& seq, sf::Vector2f& pos_out, sf::Vector2f& scale_out) {
float tick = twitching(seq);
if(stationary) {
@ -120,7 +120,6 @@ namespace animate2 {
} break;
case ease::SQUEEZE: {
scale_out.x *= std::lerp(min_x, max_x, tick);
} break;
case ease::SQUASH: {
scale_out.y *= std::lerp(min_y, max_y, tick);
@ -139,6 +138,7 @@ namespace animate2 {
dbc::sentinel("Unknown animation.motion setting.");
}
} else {
dbc::sentinel("scale should not run");
scale_out.x = std::lerp(scale_out.x * min_x, scale_out.x * max_x, tick);
scale_out.y = std::lerp(scale_out.y * min_y, scale_out.y * max_y, tick);
}