Vigilante Game Framework  1.0.0.8
A 2D/3D C++ Game Framework using SFML.
Public Member Functions | List of all members
VAnimationManager Class Reference

Handles storing and switching between multiple VAnimations. More...

#include <VAnimationManager.h>

Public Member Functions

 VAnimationManager (int TextureWidth, int TextureHeight, int FrameWidth, int FrameHeight, int OffsetX, int OffsetY)
 
sf::IntRect GetTextureArea ()
 
void AddAnimation (const sf::String &name, const std::vector< int > &Frames, float FramesPerSecond=6.0f, bool Looping=false, bool Reverse=false)
 
void AddAnimation (const sf::String &name, int Begin, int Length, float FramesPerSecond=6.0f, bool Looping=false, bool Reverse=false)
 
const sf::String & CurrentAnimationName ()
 
void Play (const sf::String &name, std::function< void()> onComplete=nullptr)
 
void SetPaused (bool value)
 
void Stop ()
 Stop all animations.
 
void Reset (std::function< void()> onComplete=nullptr)
 
void Reset (const sf::String &name, std::function< void()> onComplete=nullptr)
 
void Update (float dt)
 
void SetCurrentFrame (int NewFrame)
 
int GetCurrentFrame ()
 
int GetLastFrame ()
 
void SetLooping (bool Looping)
 
void SetReverse (bool Reverse)
 
int GetU ()
 
int GetV ()
 
void Clear ()
 Clears entire animation list.
 
int Count ()
 

Detailed Description

Handles storing and switching between multiple VAnimations.

Constructor & Destructor Documentation

◆ VAnimationManager()

VAnimationManager::VAnimationManager ( int  TextureWidth,
int  TextureHeight,
int  FrameWidth,
int  FrameHeight,
int  OffsetX,
int  OffsetY 
)
Parameters
TextureWidthThe width of the texture in pixels being used, or the partial width if the entire texture won't be used.
TextureHeightThe height of the texture in pixels being used, or the partial height if the entire texture won't be used.
FrameWidthThe width of a single frame in pixels.
FrameHeightThe height of a single frame in pixels.
OffsetXThe offset of the X axis in pixels, imporant if the area of animation is not the entire texture.
OffsetYThe offset of the Y axis in pixels, imporant if the area of animation is not the entire texture.

Member Function Documentation

◆ AddAnimation() [1/2]

void VAnimationManager::AddAnimation ( const sf::String &  name,
const std::vector< int > &  Frames,
float  FramesPerSecond = 6.0f,
bool  Looping = false,
bool  Reverse = false 
)

Adds a new animation to the manager. If an animation under the name already exists, then a new VAnimation will replace it.

Parameters
nameName of animation, used for the ID in the animation list.
FramesFrames The list of Frames the animation will have, you can pass in an std::vector<int> object or an array of ints using braces (e.g. { 0, 3, 7, 8 }).
FramesPerSecondThe amount of frames to play per second in time. This gets converted to a frameDelay using 1 / FramesPerSecond. Must be greater than 0.
LoopingWhether the animation should loop or not.
ReverseWhether the animation should reverse or not.

◆ AddAnimation() [2/2]

void VAnimationManager::AddAnimation ( const sf::String &  name,
int  Begin,
int  Length,
float  FramesPerSecond = 6.0f,
bool  Looping = false,
bool  Reverse = false 
)

Adds a new animation to the manager. If an animation under the name already exists, then a new VAnimation will replace it. Unlike the other method, this one allows will set up a list of frames is of a range of numbers, to save passing in a std::vector<int>.

Parameters
nameName of animation, used for the ID in the animation list.
BeginThe beginning frame number of the animation.
LengthThe total amount of frames this animation will have. (e.g. if Begin is 0 and Length is 5, the frame list created will be { 0, 1, 2, 3, 4 })
FramesPerSecondThe amount of frames to play per second in time. This gets converted to a frameDelay using 1 / FramesPerSecond. Must be greater than 0.
LoopingWhether the animation should loop or not.
ReverseWhether the animation should reverse or not.

◆ Count()

int VAnimationManager::Count ( )
Returns
Returns the amount of animations being stored in the animation manager.

◆ CurrentAnimationName()

const sf::String& VAnimationManager::CurrentAnimationName ( )
Returns
returns the String name/id of the currently playing animation.

◆ GetCurrentFrame()

int VAnimationManager::GetCurrentFrame ( )
Returns
The currently used frame number, regardless of whether an animation is currently being used or not.

◆ GetLastFrame()

int VAnimationManager::GetLastFrame ( )
Returns
The previous frame used in the last game's loop.

◆ GetTextureArea()

sf::IntRect VAnimationManager::GetTextureArea ( )
Returns
An sf::IntRect of the entire area of the texture where the animation is used.

◆ GetU()

int VAnimationManager::GetU ( )
Returns
Returns the current U/X coordinate of the texture for rendering purposes.

◆ GetV()

int VAnimationManager::GetV ( )
Returns
Returns the current V/Y coordinate of the texture for rendering purposes.

◆ Play()

void VAnimationManager::Play ( const sf::String &  name,
std::function< void()>  onComplete = nullptr 
)

Plays an animation. If the animation specified is already being played then nothing will happen. If you wish to replay the current animation, use the Reset function.

Parameters
nameThe name/id of the animation you wish to play. Must be an animation previously added to the scene.
onCompleteA callback function, used when the animation is completed.

◆ Reset() [1/2]

void VAnimationManager::Reset ( std::function< void()>  onComplete = nullptr)

Resets the current animation being played.

Parameters
onCompleteA callback function, used when the animation is completed.

◆ Reset() [2/2]

void VAnimationManager::Reset ( const sf::String &  name,
std::function< void()>  onComplete = nullptr 
)

Resets one of the animations in the manager.

Parameters
nameThe name/id of the animation to use.
onCompleteA callback function, used when the animation is completed.

◆ SetCurrentFrame()

void VAnimationManager::SetCurrentFrame ( int  NewFrame)

Sets the current frame index the current animation. Do not use this to set the current animation's frame number, as this is specified in the current animation's frame list. The only exception is if no current animation has been set, then the frame number can be passed in.

Parameters
NewFrameThe frame index the current animation should use. This must be greater than 0 and less than the total amount of frames specified in the current animation's frame list.

◆ SetLooping()

void VAnimationManager::SetLooping ( bool  Looping)
Parameters
LoopingIf true, the current animation will now loop, else it won't loop.

◆ SetPaused()

void VAnimationManager::SetPaused ( bool  value)
Parameters
valueTrue pauses the current animation, False resumes the current animation.

◆ SetReverse()

void VAnimationManager::SetReverse ( bool  Reverse)
Parameters
ReverseIf true, the current animation will now play in reverse, else it won't.

◆ Update()

void VAnimationManager::Update ( float  dt)

Updates the current animation, assuming pause isn't set to true.

Parameters
dtDelta Time between the current and previous frame in the game.

The documentation for this class was generated from the following file: