Animation API getting better but now need to resolve how it works with the frames.

This commit is contained in:
Zed A. Shaw 2026-01-30 23:26:35 -05:00
parent 785d0240da
commit d4e79f1d3d
7 changed files with 70 additions and 45 deletions

View file

@ -156,15 +156,15 @@ animate2::Sheet sheet{
};
animate2::Sequence sequence{
.frames{0,1},
.durations{166ms, 266ms}
.frames{0,1,0,1},
.durations{166ms, 266ms, 166ms, 266ms}
};
animate2::Transform transform{
.min_x{-20.0f},
.min_y{-20.0f},
.max_x{20.0f},
.max_y{20.0f},
animate2::Transform scale_tr{
.min_x{0.6f},
.min_y{0.6f},
.max_x{0.8f},
.max_y{0.8f},
.simple{false},
.flipped{false},
.ease_rate{0.5f},
@ -173,8 +173,25 @@ animate2::Transform transform{
.stationary{true},
.toggled{false},
.looped{true},
.easing = ease2::out_bounce,
.motion = ease2::move_bounce,
.easing = ease2::out_circle,
.motion = ease2::move_rush,
};
animate2::Transform move_tr{
.min_x{-20.0f},
.min_y{-20.0f},
.max_x{20.0f},
.max_y{20.0f},
.simple{false},
.flipped{false},
.ease_rate{2.5f},
.speed{0.02f},
.scaled{true},
.stationary{true},
.toggled{false},
.looped{true},
.easing = ease2::normal_dist,
.motion = ease2::move_shake,
};
int main(int argc, char* argv[]) {
@ -194,35 +211,27 @@ int main(int argc, char* argv[]) {
animator::FSM main;
main.init(argv[1]);
animate2::Animate2 anim{sheet, sequence, transform};
animate2::Timer timer;
timer.start();
animate2::Animate2 anim{sheet, sequence, scale_tr};
anim.play();
auto sprite = main.$ui.get_sprite();
sf::Vector2f pos = sprite->getPosition();
sf::Vector2f scale = sprite->getScale();
// need to keep these aroung
auto pos = sprite->getPosition();
auto scale = sprite->getScale();
while(main.active()) {
auto [ticks, alpha] = timer.commit();
fmt::println("TICK: {}, alpha: {}", ticks, alpha);
auto [ticks, alpha] = anim.commit();
for(int i = 0; i < ticks; i++) {
main.event(game::Event::TICK, {});
anim.update();
anim.apply(*sprite);
anim.motion(*sprite, pos, scale);
}
anim.apply(*sprite);
sf::Vector2f new_pos = pos;
sf::Vector2f new_scale = scale;
anim.motion(new_pos, new_scale, alpha);
sprite->setPosition(new_pos);
sprite->setScale(new_scale);
main.render();
// do something with alpha....
main.handle_keyboard_mouse();
}