diff --git a/animation.cpp b/animation.cpp index ed6af21..01d7879 100644 --- a/animation.cpp +++ b/animation.cpp @@ -102,6 +102,23 @@ namespace components { scale_out.x *= -1; } } + + bool Animation::apply(sf::Sprite& sprite, sf::Vector2f pos) { + sf::IntRect rect{{0,0}, {frame_width, frame_height}}; + sf::Vector2f scale{min_x, min_y}; + + step(scale, pos, rect); + + sprite.setTextureRect(rect); + sprite.setPosition(pos); + + // BUG: make this an option: apply_scale, apply_position and ranges for x y + if(scaled) { + sprite.setScale(scale); + } + + return playing; + } } namespace animation { @@ -111,23 +128,6 @@ namespace animation { static AnimationManager MGR; static bool initialized = false; - bool apply(Animation& anim, sf::Sprite& sprite, sf::Vector2f pos) { - sf::IntRect rect{{0,0}, {anim.frame_width, anim.frame_height}}; - sf::Vector2f scale{anim.min_x, anim.min_y}; - - anim.step(scale, pos, rect); - - sprite.setTextureRect(rect); - sprite.setPosition(pos); - - // BUG: make this an option: apply_scale, apply_position and ranges for x y - if(anim.scaled) { - sprite.setScale(scale); - } - - return anim.playing; - } - void rotate(sf::Sprite& target, float degrees) { target.rotate(sf::degrees(degrees)); } diff --git a/animation.hpp b/animation.hpp index f89496a..cbe0d62 100644 --- a/animation.hpp +++ b/animation.hpp @@ -11,7 +11,6 @@ namespace animation { std::unordered_map animations; }; - bool apply(components::Animation& anim, sf::Sprite& target, sf::Vector2f pos); void rotate(sf::Sprite& target, float degrees); void center(sf::Sprite& target, sf::Vector2f pos); diff --git a/assets/animations.json b/assets/animations.json index be39692..7fe21d0 100644 --- a/assets/animations.json +++ b/assets/animations.json @@ -292,16 +292,16 @@ "test_zoom": { "_type": "Animation", "easing": 6, - "motion": 5, + "motion": 1, "ease_rate": 0.5, - "min_x": 1.0, - "min_y": 1.0, - "max_x": 1.2, - "max_y": 1.2, + "min_x": -10.0, + "min_y": -10.0, + "max_x": 10.0, + "max_y": 10.0, "simple": true, "frames": 1, "speed": 0.01, - "scaled": true, + "scaled": false, "stationary": true, "toggled": false, "flipped": false, diff --git a/boss/ui.cpp b/boss/ui.cpp index 6d37d49..99ba366 100644 --- a/boss/ui.cpp +++ b/boss/ui.cpp @@ -92,7 +92,7 @@ namespace boss { rect.size.x, rect.size.y); sf::View zoom{pos, - {float(cell.w * 2), float(cell.h * 2)}}; + {BOSS_VIEW_WIDTH/2, BOSS_VIEW_HEIGHT/2}}; if($zoom_anim.scaled) { zoom.zoom(scale.x); diff --git a/components.hpp b/components.hpp index fe3500a..497ce9c 100644 --- a/components.hpp +++ b/components.hpp @@ -5,6 +5,7 @@ #include "point.hpp" #include #include +#include #include #include #include @@ -138,6 +139,7 @@ namespace components { int frame_width = -1; int frame_height = -1; + bool apply(sf::Sprite& target, sf::Vector2f pos); void play(); float twitching(); void step(sf::Vector2f& scale_out, sf::Vector2f& pos_out, sf::IntRect& rect_out); diff --git a/gui/main_ui.cpp b/gui/main_ui.cpp index 56844aa..3a5892b 100644 --- a/gui/main_ui.cpp +++ b/gui/main_ui.cpp @@ -145,7 +145,7 @@ namespace gui { } void MainUI::render_hands() { - if(animation::apply($hand_anim, *$hand.sprite, {0,0})) { + if($hand_anim.apply(*$hand.sprite, {0,0})) { $hand.sprite->setPosition({RAY_VIEW_X, RAY_VIEW_Y}); $window.draw(*$hand.sprite); } diff --git a/gui/ritual_ui.cpp b/gui/ritual_ui.cpp index a446305..94e0e61 100644 --- a/gui/ritual_ui.cpp +++ b/gui/ritual_ui.cpp @@ -94,7 +94,7 @@ namespace gui { void UI::OPENING(Event ev) { if(ev == Event::TICK) { - if(!animation::apply($ritual_anim, *$ritual_ui.sprite, {0,0})) { + if(!$ritual_anim.apply(*$ritual_ui.sprite, {0,0})) { state(State::OPENED); } } diff --git a/scene.cpp b/scene.cpp index 6700d57..2028773 100644 --- a/scene.cpp +++ b/scene.cpp @@ -100,13 +100,13 @@ namespace scene { void Engine::play_animations() { for(auto& fixture : $fixtures) { if(fixture.anim.playing) { - animation::apply(fixture.anim, *fixture.st.sprite, fixture.pos); + fixture.anim.apply(*fixture.st.sprite, fixture.pos); } } for(auto& actor : $actors) { if(actor.anim.playing) { - animation::apply(actor.anim, *actor.st.sprite, actor.pos); + actor.anim.apply(*actor.st.sprite, actor.pos); } } } diff --git a/tests/animation.cpp b/tests/animation.cpp index ad6f6a4..42a4df2 100644 --- a/tests/animation.cpp +++ b/tests/animation.cpp @@ -42,7 +42,7 @@ TEST_CASE("animation utility API", "[animation]") { anim.play(); - while(animation::apply(anim, *blanket.sprite, {0,0})) { + while(anim.apply(*blanket.sprite, {0,0})) { fmt::println("animation: {}", anim.subframe); } } diff --git a/tests/animation2.cpp b/tests/animation2.cpp index d654c20..3d96f42 100644 --- a/tests/animation2.cpp +++ b/tests/animation2.cpp @@ -32,7 +32,7 @@ struct AnimationState { } void apply(textures::SpriteTexture& st) { - animation::apply(anim, *st.sprite, pos); + anim.apply(*st.sprite, pos); } };