ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
Loading...
Searching...
No Matches
sprite_sheet.h
Go to the documentation of this file.
1
8
9#ifndef ASW_SPRITE_SHEET_H
10#define ASW_SPRITE_SHEET_H
11
12#include "./geometry.h"
13#include "./types.h"
14
15namespace asw {
16
21public:
24 SpriteSheet() = default;
25
34
39 const Texture& get_texture() const;
40
46
51 int get_frame_count() const;
52
58 Quad<float> get_frame(int index) const;
59
65 void draw_frame(int index, const Quad<float>& dest) const;
66
67private:
70 int columns { 0 };
71 int frame_count { 0 };
72};
73
76class Animation {
77public:
80 Animation() = default;
81
88 Animation(int frame_count, float frame_duration, bool loop = true);
89
94 void update(float dt);
95
98 void reset();
99
105
110 int get_frame() const;
111
116 bool is_finished() const;
117
118private:
119 int frame_count { 1 };
120 float frame_duration { 0.1F };
121 bool loop { true };
122 float elapsed { 0.0F };
123};
124
125} // namespace asw
126
127#endif // ASW_SPRITE_SHEET_H
Steps through frames over time, to use with a SpriteSheet.
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.
A 2D rectangle in space.
Definition geometry.h:504
A texture split into equal frames, read left to right then top to bottom.
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 > frame_size
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.
A 2D vector in space.
Definition geometry.h:27
Common geometry types.
Definition camera.cpp:16
std::shared_ptr< SDL_Texture > Texture
Alias for a shared pointer to an SDL_Texture.
Definition types.h:76
Types used throughout the ASW library.