From 1c2a216055a107c1ce8d9d6845be80df0e0764f4 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Sun, 13 Nov 2022 20:39:55 +0100 Subject: Add flipped animations ftw --- src/graphics/animation.h | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/graphics') 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 FlippedAnimation : public T{ + static_assert(std::is_base_of::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 -- cgit v1.2.3