21 , frame_size(frame_size)
29 const int rows = std::max(1,
static_cast<int>(std::floor(texture_size.y /
frame_size.
y)));
30 const int fits =
columns * rows;
58 const auto column =
static_cast<float>(frame %
columns);
59 const auto row =
static_cast<float>(frame /
columns);
74 : frame_count(std::max(1, frame_count))
75 , frame_duration(std::max(0.0001F, frame_duration))
bool is_finished() const
Check if a non looping animation has reached its last frame.
void update(float dt)
Advance the animation.
int get_frame() const
Get the frame to draw.
void set_frame_duration(float frame_duration)
Set seconds each frame is shown.
Animation()=default
Create an animation with a single frame.
void reset()
Go back to the first frame.
int get_frame_count() const
Get the number of frames.
Quad< float > get_frame(int index) const
Get the area of the texture a frame covers.
SpriteSheet()=default
Create an empty sprite sheet.
Vec2< float > get_frame_size() const
Get the size of one frame.
const Texture & get_texture() const
Get the texture.
void draw_frame(int index, const Quad< float > &dest) const
Draw a frame stretched to an area of the screen.
T y
The y component of the vector.
T x
The x component of the vector.
Routines for drawing sprites and primitives to the screen.
void stretch_sprite_blit(const asw::Texture &tex, const asw::Quad< float > &source, const asw::Quad< float > &dest)
Draw a sprite with the option to stretch a portion of it.
asw::Vec2< float > get_texture_size(const asw::Texture &tex)
Get texture size.
std::shared_ptr< SDL_Texture > Texture
Alias for a shared pointer to an SDL_Texture.
Sprite sheets and frame animation.
General utility functions.