Muto 0.0.1
Cross-Platform Application Template
GitHub Repo | Muto Updates | Muto's Author
Loading...
Searching...
No Matches
Muto::TextureAnimationComponent Struct Reference

Animates through a series of sub textures. More...

#include <Components.h>

Public Member Functions

int GetCurrentFrame () const
 Returns the index of the current frame.
 
Ref< SubTexture2D > GetCurrentSubTexture ()
 
std::vector< Ref< SubTexture2D > > & GetSubTextures ()
 
 operator const std::vector< Ref< SubTexture2D > > & () const
 
 operator std::vector< Ref< SubTexture2D > > & ()
 
 TextureAnimationComponent ()=default
 
 TextureAnimationComponent (const std::vector< Ref< SubTexture2D > > &subTextures, float frameTime)
 Constructor that initializes the sub-textures and frame time.
 
 TextureAnimationComponent (const TextureAnimationComponent &)=default
 
void Update (float deltaTime)
 Updates the animation based on the elapsed time.
 

Public Attributes

int CurrentFrame = 0
 The current frame index.
 
float FrameTime = 0.6f
 Time per frame in seconds.
 
bool IsLooping = true
 
std::vector< Ref< SubTexture2D > > SubTextures
 The list of sub-textures for the animation.
 
float TimeAccumulator = 0.0f
 Accumulated time for frame switching.
 

Detailed Description

Animates through a series of sub textures.

(can be used with full textures)

Constructor & Destructor Documentation

◆ TextureAnimationComponent() [1/3]

Muto::TextureAnimationComponent::TextureAnimationComponent ( )
default

◆ TextureAnimationComponent() [2/3]

Muto::TextureAnimationComponent::TextureAnimationComponent ( const TextureAnimationComponent &  )
default

◆ TextureAnimationComponent() [3/3]

Muto::TextureAnimationComponent::TextureAnimationComponent ( const std::vector< Ref< SubTexture2D > > &  subTextures,
float  frameTime 
)
inline

Constructor that initializes the sub-textures and frame time.

Parameters
subTexturesVector of sub-textures for the animation.
frameTimeTime per frame in seconds.
192 }
constexpr Scope< T > CreateScope(Args &&... args)
Creates a Scope (unique_ptr) for the given type and constructor arguments.
Definition Defines_Macros.h:51
float FrameTime
Time per frame in seconds.
Definition Components.h:177
std::vector< Ref< SubTexture2D > > SubTextures
The list of sub-textures for the animation.
Definition Components.h:173

References FrameTime, and TextureAnimationComponent().

Referenced by TextureAnimationComponent().

Member Function Documentation

◆ GetCurrentFrame()

int Muto::TextureAnimationComponent::GetCurrentFrame ( ) const
inline

Returns the index of the current frame.

206{ return CurrentFrame; }
int CurrentFrame
The current frame index.
Definition Components.h:175

◆ GetCurrentSubTexture()

Ref< SubTexture2D > Muto::TextureAnimationComponent::GetCurrentSubTexture ( )
inline
196 {
197 if (SubTextures.empty())
198 return nullptr;
199 if (CurrentFrame < 0) CurrentFrame = 0;
200 if (CurrentFrame >= (int)SubTextures.size()) CurrentFrame = (int)SubTextures.size() - 1;
201 return SubTextures[CurrentFrame];
202 }

◆ GetSubTextures()

std::vector< Ref< SubTexture2D > > & Muto::TextureAnimationComponent::GetSubTextures ( )
inline
203{ return SubTextures; }

◆ operator const std::vector< Ref< SubTexture2D > > &()

Muto::TextureAnimationComponent::operator const std::vector< Ref< SubTexture2D > > & ( ) const
inline
194{ return SubTextures; }

◆ operator std::vector< Ref< SubTexture2D > > &()

Muto::TextureAnimationComponent::operator std::vector< Ref< SubTexture2D > > & ( )
inline
193{ return SubTextures; }

◆ Update()

void Muto::TextureAnimationComponent::Update ( float  deltaTime)
inline

Updates the animation based on the elapsed time.

Parameters
deltaTimeThe elapsed time since the last update.
211 {
212 if (SubTextures.empty() || FrameTime <= 0.0f)
213 return;
214
216 while (TimeAccumulator >= FrameTime) {
217 CurrentFrame = (CurrentFrame + 1) % static_cast<uint32_t>(SubTextures.size());
219 }
220 }
float TimeAccumulator
Accumulated time for frame switching.
Definition Components.h:179

Member Data Documentation

◆ CurrentFrame

int Muto::TextureAnimationComponent::CurrentFrame = 0

The current frame index.

Referenced by Muto::TextureAnimationEdit().

◆ FrameTime

float Muto::TextureAnimationComponent::FrameTime = 0.6f

Time per frame in seconds.

Referenced by TextureAnimationComponent().

◆ IsLooping

bool Muto::TextureAnimationComponent::IsLooping = true

◆ SubTextures

std::vector<Ref<SubTexture2D> > Muto::TextureAnimationComponent::SubTextures

The list of sub-textures for the animation.

◆ TimeAccumulator

float Muto::TextureAnimationComponent::TimeAccumulator = 0.0f

Accumulated time for frame switching.


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