All of the original features now work: simple, flipped, scaled, toggled, looped and stationary is replaced by ease2::scale_only.

This commit is contained in:
Zed A. Shaw 2026-01-31 11:40:45 -05:00
parent 34e4a34f65
commit ca335d21e5
4 changed files with 25 additions and 11 deletions

View file

@ -35,6 +35,8 @@ namespace animate2 {
// need one for each kind of thing to animate
// NOTE: possibly find a way to only run apply on frame change?
void Animate2::apply(sf::Sprite& sprite) {
dbc::check(!$transform.simple, "can't call ::apply() on a simple animation, only ::motion()");
dbc::check($sequence.current < $frame_rects.size(), "current frame past $frame_rects");
// NOTE: pos is not updated yet
auto& rect = $frame_rects.at($sequence.current);
@ -76,8 +78,15 @@ namespace animate2 {
void Animate2::motion(sf::Sprite& sprite, sf::Vector2f pos, sf::Vector2f scale) {
$transform.lerp($sequence, pos, scale);
if($transform.flipped) {
scale.x *= -1;
}
sprite.setPosition(pos);
sprite.setScale(scale);
if($transform.scaled) {
sprite.setScale(scale);
}
}
std::pair<int, double> Animate2::commit() {

View file

@ -53,8 +53,8 @@ namespace animate2 {
bool flipped{false};
float ease_rate{0.5f};
bool scaled{false};
bool stationary{false};
// these can handled by the onLoop, same as ganim8 does it
// handled by onLoop
bool toggled{false};
bool looped{false};
@ -71,7 +71,12 @@ namespace animate2 {
using OnFrameHandler = std::function<void()>;
inline bool DefaultOnLoop(Sequence& seq, Transform& tr) {
seq.current = 0;
if(tr.toggled) {
seq.current = seq.frame_count - 1;
} else {
seq.current = 0;
}
return tr.looped;
}

View file

@ -40,7 +40,6 @@ Animate2 crafter() {
.flipped{false},
.ease_rate{0.5f},
.scaled{true},
.stationary{true},
.toggled{false},
.looped{false},
.easing = ease2::in_out_back,

View file

@ -169,11 +169,10 @@ animate2::Transform scale_tr{
.flipped{false},
.ease_rate{1.0f/0.2f},
.scaled{true},
.stationary{true},
.toggled{false},
.looped{true},
.easing = ease2::in_out_back,
.motion = ease2::move_rush,
.motion = ease2::scale_only,
};
animate2::Transform move_tr{
@ -185,7 +184,6 @@ animate2::Transform move_tr{
.flipped{false},
.ease_rate{2.5f},
.scaled{true},
.stationary{true},
.toggled{false},
.looped{true},
.easing = ease2::normal_dist,
@ -223,9 +221,12 @@ int main(int argc, char* argv[]) {
for(int i = 0; i < ticks; i++) {
main.event(game::Event::TICK, {});
anim.update();
anim.apply(*sprite);
anim.motion(*sprite, pos, scale);
if(anim.playing) {
anim.update();
anim.apply(*sprite);
anim.motion(*sprite, pos, scale);
}
}
main.render();