A class that handles sprite animations.
More...
#include <Animation.hpp>
|
| | Animation (sf::Vector2u textureSize={0, 0}) |
| | Constructor for Animation class.
|
| |
|
| ~Animation () |
| | Destructor for Animation class.
|
| |
| void | setTextureSize (sf::Vector2u textureSize) |
| | Sets the texture size for the animation.
|
| |
| bool | addAnimation (const std::string &name, int frameCount, sf::Vector2u frameSize, sf::Vector2u startPosition, float fps=12.0f, bool loop=true) |
| | Adds an animation to the animation list.
|
| |
| bool | setCurrentAnimation (const std::string &name, bool resetFrame=true) |
| | Sets the current animation.
|
| |
| void | update (float deltaTime) |
| | Updates the animation based on elapsed time.
|
| |
|
void | play () |
| | Plays the current animation.
|
| |
|
void | pause () |
| | Pauses the current animation.
|
| |
| void | stop () |
| | Stops the current animation and resets it.
|
| |
| bool | isPlaying () const |
| | Checks if the animation is playing.
|
| |
| std::string | getCurrentAnimationName () const |
| | Gets the current animation name.
|
| |
| void | setFlipX (bool flip) |
| | Sets whether the sprite should be flipped horizontally.
|
| |
| void | setFlipY (bool flip) |
| | Sets whether the sprite should be flipped vertically.
|
| |
| const sf::IntRect & | getTextureRect () const |
| | Gets the texture rectangle for the current frame.
|
| |
|
|
sf::IntRect | _textureRect |
| |
|
sf::Vector2u | _textureSize |
| |
|
std::unordered_map< std::string, AnimationData > | _animations |
| |
|
std::string | _currentAnimationName |
| |
|
int | _currentFrame |
| |
|
float | _timeAccumulator |
| |
|
bool | _isPlaying |
| |
|
bool | _flipX |
| |
|
bool | _flipY |
| |
A class that handles sprite animations.
◆ Animation()
| Animation |
( |
sf::Vector2u | textureSize = {0, 0} | ) |
|
Constructor for Animation class.
- Parameters
-
| textureSize | Size of the texture (default is {0, 0}) |
◆ addAnimation()
| bool addAnimation |
( |
const std::string & | name, |
|
|
int | frameCount, |
|
|
sf::Vector2u | frameSize, |
|
|
sf::Vector2u | startPosition, |
|
|
float | fps = 12.0f, |
|
|
bool | loop = true ) |
Adds an animation to the animation list.
- Parameters
-
| name | Name of the animation |
| frameCount | Number of frames in the animation |
| frameSize | Size of each frame |
| startPosition | Starting position of the animation in the sprite sheet |
| fps | Frames per second for the animation (default is 12.0f) |
| loop | Whether the animation should loop (default is true) |
- Returns
- True if the animation was added successfully and false otherwise
◆ getCurrentAnimationName()
| std::string getCurrentAnimationName |
( |
| ) |
const |
Gets the current animation name.
- Returns
- Name of the current animation
-
The current animation name
◆ getTextureRect()
| const sf::IntRect & getTextureRect |
( |
| ) |
const |
Gets the texture rectangle for the current frame.
- Returns
- The texture rectangle for the current frame
◆ isPlaying()
Checks if the animation is playing.
- Returns
- True if the animation is playing
◆ setCurrentAnimation()
| bool setCurrentAnimation |
( |
const std::string & | name, |
|
|
bool | resetFrame = true ) |
Sets the current animation.
- Parameters
-
| name | Name of the animation to set |
| resetFrame | Whether to start the animation from the beginning (default is true) |
- Returns
- True if the animation was set successfully and false otherwise
◆ setFlipX()
| void setFlipX |
( |
bool | flip | ) |
|
Sets whether the sprite should be flipped horizontally.
- Parameters
-
| flip | True to flip the sprite horizontally |
◆ setFlipY()
| void setFlipY |
( |
bool | flip | ) |
|
Sets whether the sprite should be flipped vertically.
- Parameters
-
| flip | True to flip the sprite vertically |
◆ setTextureSize()
| void setTextureSize |
( |
sf::Vector2u | textureSize | ) |
|
Sets the texture size for the animation.
- Parameters
-
| textureSize | Size of the texture |
◆ stop()
Stops the current animation and resets it.
Stops the current animation.
◆ update()
| void update |
( |
float | deltaTime | ) |
|
Updates the animation based on elapsed time.
- Parameters
-
| deltaTime | Elapsed time since last update |
◆ updateTextureRect()
| void updateTextureRect |
( |
| ) |
|
|
private |
Updates the texture rectangle for the current frame.
- Returns
- The updated texture rectangle
The documentation for this class was generated from the following files: