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
asw::SpriteSheet Class Reference

A texture split into equal frames, read left to right then top to bottom. More...

#include <sprite_sheet.h>

Collaboration diagram for asw::SpriteSheet:
[legend]

Public Member Functions

 SpriteSheet ()=default
 Create an empty sprite sheet.
 
 SpriteSheet (const Texture &texture, const Vec2< float > &frame_size, int frame_count=0)
 Create a sprite sheet.
 
const Texture & get_texture () const
 Get the texture.
 
Vec2< float > get_frame_size () const
 Get the size of one 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.
 
void draw_frame (int index, const Quad< float > &dest) const
 Draw a frame stretched to an area of the screen.
 

Private Attributes

Texture texture
 
Vec2< float > frame_size
 
int columns { 0 }
 
int frame_count { 0 }
 

Detailed Description

A texture split into equal frames, read left to right then top to bottom.

Definition at line 20 of file sprite_sheet.h.

Constructor & Destructor Documentation

◆ SpriteSheet() [1/2]

asw::SpriteSheet::SpriteSheet ( )
default

Create an empty sprite sheet.

◆ SpriteSheet() [2/2]

asw::SpriteSheet::SpriteSheet ( const Texture & texture,
const Vec2< float > & frame_size,
int frame_count = 0 )

Create a sprite sheet.

Parameters
textureThe texture holding the frames.
frame_sizeThe size of one frame in pixels.
frame_countThe number of frames, 0 to use every frame that fits in the texture.

Definition at line 19 of file sprite_sheet.cpp.

Member Function Documentation

◆ draw_frame()

void asw::SpriteSheet::draw_frame ( int index,
const Quad< float > & dest ) const

Draw a frame stretched to an area of the screen.

Parameters
indexThe frame, wraps around past the last frame.
destThe area to draw to.

Definition at line 64 of file sprite_sheet.cpp.

◆ get_frame()

Quad< float > asw::SpriteSheet::get_frame ( int index) const

Get the area of the texture a frame covers.

Parameters
indexThe frame, wraps around past the last frame.
Returns
The source area in pixels.

Definition at line 50 of file sprite_sheet.cpp.

◆ get_frame_count()

int asw::SpriteSheet::get_frame_count ( ) const

Get the number of frames.

Returns
The frame count.

Definition at line 45 of file sprite_sheet.cpp.

◆ get_frame_size()

Vec2< float > asw::SpriteSheet::get_frame_size ( ) const

Get the size of one frame.

Returns
The frame size in pixels.

Definition at line 40 of file sprite_sheet.cpp.

◆ get_texture()

const Texture & asw::SpriteSheet::get_texture ( ) const

Get the texture.

Returns
The texture.

Definition at line 35 of file sprite_sheet.cpp.

Member Data Documentation

◆ columns

int asw::SpriteSheet::columns { 0 }
private

Definition at line 70 of file sprite_sheet.h.

◆ frame_count

int asw::SpriteSheet::frame_count { 0 }
private

Definition at line 71 of file sprite_sheet.h.

◆ frame_size

Vec2<float> asw::SpriteSheet::frame_size
private

Definition at line 69 of file sprite_sheet.h.

◆ texture

Texture asw::SpriteSheet::texture
private

Definition at line 68 of file sprite_sheet.h.


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