diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2022-11-13 20:39:55 +0100 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2022-11-13 20:39:55 +0100 |
commit | 1c2a216055a107c1ce8d9d6845be80df0e0764f4 (patch) | |
tree | b99b8166a4c503cb3905181449ed4d88b7c85043 /src/graphics | |
parent | f139e6c1dcdfaa79967e4f7e6c3961677019b02d (diff) |
Add flipped animations ftw
Diffstat (limited to 'src/graphics')
-rw-r--r-- | src/graphics/animation.h | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/graphics/animation.h b/src/graphics/animation.h index 010a64a..583da8a 100644 --- a/src/graphics/animation.h +++ b/src/graphics/animation.h @@ -24,12 +24,19 @@ namespace Graphics{ virtual sf::IntRect& next(int deltaTime); virtual void reset(); virtual bool finished(); + static sf::Sprite& flip(sf::Sprite &sprite){ + sf::IntRect frame = sprite.getTextureRect(); + frame.left += frame.width; + frame.width *= -1; + sprite.setTextureRect(frame); + return sprite; + }; }; class OneShotAnimation : public Animation { public: using Animation::Animation; - sf::IntRect& next(int deltaTime) override; + virtual sf::IntRect& next(int deltaTime) override; bool finished() override; }; @@ -39,7 +46,21 @@ namespace Graphics{ public: using Animation::Animation; ~BouncingAnimation(); - sf::IntRect& next(int deltaTime) override; + virtual sf::IntRect& next(int deltaTime) override; + }; + + template <class T> + class FlippedAnimation : public T{ + static_assert(std::is_base_of<Animation, T>::value, + "Base class of FlippedAnimation is not an Animation"); + public: + using T::T; + sf::IntRect& next(int deltaTime) override{ + T::next(deltaTime); + T::rect_.left = (T::i_ + 1) * T::w_; + T::rect_.width = -T::w_; + return T::rect_; + } }; } #endif // GRAPHICS_ANIMATION_H |