Manages sprite sheet animations and transitions between them using a state machine. More...
#include <Animator.h>


Classes | |
| struct | Animation |
| Represents a single, self-contained animation sequence. More... | |
| struct | Edge |
| Defines a transition edge between two animations in the state machine. More... | |
Public Member Functions | |
| void | init () override |
| Initializes the Animator component, acquiring the entity's Sprite component. | |
| void | update () override |
| Updates the current animation state, checking for transitions and advancing the frame. | |
| void | draw () override |
| Draws the current frame of the active animation. | |
| void | addAnimation (const char *id, const char *texPath, int speed=100, const bool isLooping=true, const bool isReversible=false) |
| Adds a new animation state to the animator's state machine. | |
| void | addEdge (const char *idFrom, const char *idTo, std::vector< std::shared_ptr< bool > > conditions) |
| Defines a conditional transition between two animations. | |
| std::string | getCurrAnimID () |
| Gets the ID of the currently playing animation. | |
Public Member Functions inherited from Component | |
| virtual void | reload () |
| Called to reset the component's state. | |
Additional Inherited Members | |
Public Attributes inherited from Component | |
| Entity * | entity |
| Pointer to the entity that owns this component. | |
Manages sprite sheet animations and transitions between them using a state machine.
This component controls an entity's sprite to play different animation sequences. It uses an adjacency matrix to define transitions (Edges) between animations based on conditions.
| void Animator::addAnimation | ( | const char * | id, |
| const char * | texPath, | ||
| int | speed = 100, |
||
| const bool | isLooping = true, |
||
| const bool | isReversible = false |
||
| ) |
Adds a new animation state to the animator's state machine.
| id | The unique identifier for the new animation. |
| texPath | The file path to the sprite sheet texture. |
| speed | The delay in milliseconds between frames. |
| isLooping | Whether the animation should loop. |
| isReversible | Whether the animation should play in reverse after finishing. |

| void Animator::addEdge | ( | const char * | idFrom, |
| const char * | idTo, | ||
| std::vector< std::shared_ptr< bool > > | conditions | ||
| ) |
Defines a conditional transition between two animations.
| idFrom | The ID of the source animation state. |
| idTo | The ID of the destination animation state. |
| conditions | A vector of pointers to booleans that must be true to transition. |

|
overridevirtual |
Draws the current frame of the active animation.
Reimplemented from Component.
| std::string Animator::getCurrAnimID | ( | ) |
Gets the ID of the currently playing animation.
|
overridevirtual |
|
overridevirtual |
Updates the current animation state, checking for transitions and advancing the frame.
Reimplemented from Component.
