diff --git a/animate2.cpp b/animate2.cpp index 97167f6..58abd0f 100644 --- a/animate2.cpp +++ b/animate2.cpp @@ -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 Animate2::commit() { diff --git a/animate2.hpp b/animate2.hpp index 2e7436f..0c80ce5 100644 --- a/animate2.hpp +++ b/animate2.hpp @@ -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; 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; } diff --git a/tests/animate2.cpp b/tests/animate2.cpp index db3a5c8..3314506 100644 --- a/tests/animate2.cpp +++ b/tests/animate2.cpp @@ -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, diff --git a/tools/animator.cpp b/tools/animator.cpp index 6ec5c8a..4245d0e 100644 --- a/tools/animator.cpp +++ b/tools/animator.cpp @@ -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();