From c8663de4fbdb30534723df6c8d1331535dcdadc2 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Sat, 12 Nov 2022 23:01:24 +0100 Subject: Reorganize to make animations easily changeable: Animations now return rectangles so the texture is independent from them and they don't store the sprite either. Many Animations may have the same texture. Changing from one Animation to another is just changing a reference. --- src/graphics/animation.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/graphics/animation.h') diff --git a/src/graphics/animation.h b/src/graphics/animation.h index 87b4427..9f5dfa5 100644 --- a/src/graphics/animation.h +++ b/src/graphics/animation.h @@ -9,26 +9,29 @@ namespace Graphics{ protected: int i_; int count_; + int row_; int lastTime_; int switchTime_; unsigned int w_, h_; sf::IntRect rect_; sf::Texture texture_; - sf::Sprite sprite_; bool ticked(int deltaTime); public: Animation(); ~Animation(); - Animation(const char* filename, int count, int switchTime); - sf::Sprite& next(int deltaTime); + Animation(const sf::Texture& texture, int count, int switchTime, + int height, int width, int row); + sf::IntRect& next(int deltaTime); + void reset(); }; class OneShotAnimation : Animation { public: OneShotAnimation(); - OneShotAnimation(const char* filename, int count, int switchTime); + OneShotAnimation(const sf::Texture& texture, int count, int + switchTime, int height, int width, int row); bool finished(); - sf::Sprite& next(int deltaTime); + sf::IntRect& next(int deltaTime); }; class BouncingAnimation : Animation{ @@ -36,9 +39,10 @@ namespace Graphics{ bool up_; public: BouncingAnimation(); - BouncingAnimation(const char* filename, int count, int switchTime); + BouncingAnimation(const sf::Texture& texture, int count, int + switchTime, int height, int width, int row); ~BouncingAnimation(); - sf::Sprite& next(int deltaTime); + sf::IntRect& next(int deltaTime); }; } #endif // GRAPHICS_ANIMATION_H -- cgit v1.2.3