Calamity Engine 1.0.0
A cross-platform 2D game engine written in C++ and SDL3.
Loading...
Searching...
No Matches
Animation Class Reference

#include <definitions.hpp>

Public Member Functions

 Animation (std::string _name="Animation", int _fps=30, Vector2 _size={0, 0}, bool _loop=true, bool _autoplay=false)
 
template<typename... Args>
void addFrames (Args... frames)
 
template<class Archive >
void save (Archive &ar) const
 
template<class Archive >
void load (Archive &ar)
 

Public Attributes

std::string name
 
int fps = 15
 
std::vector< Frameframes
 
std::string texturePath
 
TextureScaling textureScaling
 
Vector2 size
 
bool loop = true
 
bool autoplay = false
 

Detailed Description

Animation

The Animation component represents a series of Frame ["Frames"]. It is used with AnimatedSprite ["AnimatedSprites"].

Example usage:

// Create an animation which has the name "myAnimationName", runs at 15 FPS, has the size of 20x20 pixels, does not loop and does not autoplay.
Animation anim = Animation("myAnimationName", 15, Vector2{20.0f, 20.0f}, false, false);
Definition definitions.hpp:372
Definition definitions.hpp:77

Properties and usages

For an animation to work on an AnimatedSprite, you must set it's texturePath:

anim.texturePath = "res://path/to/texture.png";

Instead of directly storing a texture, Animations only store the path and scaling of the texture. The texture is eventually loaded when playing the animation to save on memory.

You can also define the TextureScaling type:

anim.textureScaling = TextureScaling::PIXELART;

Make sure to also check out the animated sprite example!

Constructor & Destructor Documentation

◆ Animation()

Animation::Animation ( std::string  _name = "Animation",
int  _fps = 30,
Vector2  _size = {0, 0},
bool  _loop = true,
bool  _autoplay = false 
)
inline

Member Function Documentation

◆ addFrames()

template<typename... Args>
void Animation::addFrames ( Args...  frames)
inline

◆ load()

template<class Archive >
void Animation::load ( Archive &  ar)
inline

◆ save()

template<class Archive >
void Animation::save ( Archive &  ar) const
inline

Member Data Documentation

◆ autoplay

bool Animation::autoplay = false

◆ fps

int Animation::fps = 15

◆ frames

std::vector<Frame> Animation::frames

◆ loop

bool Animation::loop = true

◆ name

std::string Animation::name

◆ size

Vector2 Animation::size

◆ texturePath

std::string Animation::texturePath

◆ textureScaling

TextureScaling Animation::textureScaling

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