Jetpack documentation 1.0.0
Loading...
Searching...
No Matches
Animation Class Reference

A class that handles sprite animations. More...

#include <Animation.hpp>

Data Structures

struct  AnimationData
 Structure to store animation data. More...
 

Public Member Functions

 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.
 

Private Member Functions

void updateTextureRect ()
 Updates the texture rectangle for the current frame.
 

Private Attributes

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
 

Detailed Description

A class that handles sprite animations.

Constructor & Destructor Documentation

◆ Animation()

Animation ( sf::Vector2u textureSize = {0, 0})

Constructor for Animation class.

Parameters
textureSizeSize of the texture (default is {0, 0})

Member Function Documentation

◆ 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
nameName of the animation
frameCountNumber of frames in the animation
frameSizeSize of each frame
startPositionStarting position of the animation in the sprite sheet
fpsFrames per second for the animation (default is 12.0f)
loopWhether 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()

bool isPlaying ( ) const

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
nameName of the animation to set
resetFrameWhether 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
flipTrue to flip the sprite horizontally

◆ setFlipY()

void setFlipY ( bool flip)

Sets whether the sprite should be flipped vertically.

Parameters
flipTrue to flip the sprite vertically

◆ setTextureSize()

void setTextureSize ( sf::Vector2u textureSize)

Sets the texture size for the animation.

Parameters
textureSizeSize of the texture

◆ stop()

void 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
deltaTimeElapsed 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: