Building Game Engines
AnimationComponent Class Reference

Provides functions to add sprites and update animation. More...

#include <AnimationComponent.hpp>

Inheritance diagram for AnimationComponent:
Inheritance graph
Collaboration diagram for AnimationComponent:
Collaboration graph

Public Member Functions

 AnimationComponent (SDL_Renderer *ren)
 Constructor. More...
 
 AnimationComponent ()
 
 ~AnimationComponent ()
 Destructor. More...
 
void Update (PLAYER_STATE targetState, PLAYER_DIR movingDir, int posX, int posY)
 Update animation state and the sprite in the source texture. More...
 
void Render (SDL_Renderer *ren)
 Render the animation to the active viewport. More...
 
void AddSprite (ANIMATION_STATE spriteName, Sprite *newSprite)
 Add sprites needed for animation. More...
 
void UpdateState (ANIMATION_STATE newState)
 Update the state of the animation. More...
 
SpriteGetCurrSprite ()
 get the currently playing sprite. This is for determining the sprite play progress as some operations like knockback relies on it. More...
 
ANIMATION_STATE GetState ()
 return the animation state. More...
 
SpriteGetSprite (ANIMATION_STATE newState)
 get a specific animation sprite More...
 
- Public Member Functions inherited from Component
 Component ()
 
 ~Component ()
 

Detailed Description

Provides functions to add sprites and update animation.

Constructor & Destructor Documentation

◆ AnimationComponent() [1/2]

AnimationComponent::AnimationComponent ( SDL_Renderer *  ren)

Constructor.

Parameters
renReference to SDL renderer.

◆ AnimationComponent() [2/2]

AnimationComponent::AnimationComponent ( )

◆ ~AnimationComponent()

AnimationComponent::~AnimationComponent ( )

Destructor.

Member Function Documentation

◆ AddSprite()

void AnimationComponent::AddSprite ( ANIMATION_STATE  spriteName,
Sprite newSprite 
)

Add sprites needed for animation.

◆ GetCurrSprite()

Sprite * AnimationComponent::GetCurrSprite ( )

get the currently playing sprite. This is for determining the sprite play progress as some operations like knockback relies on it.

Returns
spritePointer

◆ GetSprite()

Sprite * AnimationComponent::GetSprite ( ANIMATION_STATE  newState)

get a specific animation sprite

Parameters
newStateCurrent animation state.
Returns
spritePointer the sprite corresponding to the given state

◆ GetState()

ANIMATION_STATE AnimationComponent::GetState ( )

return the animation state.

Returns
ANIMATION_STATE describes which sprite is playing, like WALK or RUN.

◆ Render()

void AnimationComponent::Render ( SDL_Renderer *  ren)

Render the animation to the active viewport.

Parameters
renReference to SDL renderer.

◆ Update()

void AnimationComponent::Update ( PLAYER_STATE  targetState,
PLAYER_DIR  movingDir,
int  posX,
int  posY 
)

Update animation state and the sprite in the source texture.

Parameters
targetStateThe state of the gameobject in the next frame.
movingDirMoving direction.
posXThe x location of the sprite in the source texture.
posYThe y location of the sprite in the source texture.

◆ UpdateState()

void AnimationComponent::UpdateState ( ANIMATION_STATE  newState)

Update the state of the animation.

Parameters
newStateThe new animation state.