/* * Sprite.h * * Created on: Nov 29, 2016 * Author: tibi */ #ifndef MODEL_SPRITE_H_ #define MODEL_SPRITE_H_ #include #include #include namespace farmlands { namespace base { /** * Defines an animation frame */ struct Frame { uint32_t tileSetId; uint32_t tileSetCell; uint32_t width, height; uint32_t duration; }; /** * Defines a sprite state (aka an animation). */ struct SpriteState { std::string name; std::vector frames; }; /** * Defines a sprite */ class Sprite { public: Sprite(); virtual ~Sprite(); /** * Adds a state to the sprite. */ void addState(const SpriteState& state); /** * Sets the current state. */ void setState(size_t stateId); /** * Sets the current state. */ void setState(const std::string& name); /** * Advances the current frame */ void advanceTime(uint32_t steps); // Getters SpriteState& currentState(); Frame& currentFrame(); // Public fields float anchorX, anchorY; std::string name; private: std::vector m_states; std::unordered_map m_stateNames; size_t m_currentState; size_t m_currentFrame; uint32_t m_currentFrameTimeLeft; }; } /* namespace model */ } /* namespace farmlands */ #endif /* MODEL_SPRITE_H_ */