Sprite class. More...

#include <sprite.h>

Public Types

enum  ShowOnFinish { show_blank , show_last_frame , show_first_frame }
 

Public Member Functions

 Sprite ()
 Constructs a null instance.
 
 Sprite (Canvas &canvas)
 Constructs an empty Sprite.
 
 Sprite (Canvas &canvas, const std::string &filename, const FileSystem &file_system, const ImageImportDescription &import_desc=ImageImportDescription())
 Constructs a Sprite.
 
 Sprite (Canvas &canvas, const std::string &fullname, const ImageImportDescription &import_desc=ImageImportDescription())
 Constructs a Sprite.
 
 Sprite (Canvas &canvas, IODevice &file, const std::string &image_type, const ImageImportDescription &import_desc=ImageImportDescription())
 Constructs a Sprite.
 
virtual ~Sprite ()
 
void add_alphaclipped_frames (Canvas &canvas, const Texture2D &texture, int xpos=0, int ypos=0, float trans_limit=0.05f)
 Adds images separated with pure alpha (within trans_limit).
 
void add_alphaclipped_frames_free (Canvas &canvas, const Texture2D &texture, int xpos=0, int ypos=0, float trans_limit=0.05f)
 Adds images separated with pure alpha (within trans_limit).
 
void add_frame (Canvas &canvas, const std::string &filename, const FileSystem &file_system, const ImageImportDescription &import_desc=ImageImportDescription())
 Add frame.
 
void add_frame (Canvas &canvas, const std::string &fullname, const ImageImportDescription &import_desc=ImageImportDescription())
 Add frame.
 
void add_frame (Canvas &canvas, IODevice &file, const std::string &image_type, const ImageImportDescription &import_desc=ImageImportDescription())
 Add frame.
 
void add_frame (const Texture2D &texture)
 Add frame.
 
void add_frame (const Texture2D &texture, const Rect &frame)
 Add frame.
 
void add_frames (const Texture2D &texture, Rect *frames, int num_frames)
 Add frames.
 
void add_gridclipped_frames (Canvas &canvas, const Texture2D &texture, int xpos, int ypos, int width, int height, int xarray=1, int yarray=1, int array_skipframes=0, int xspacing=0, int yspacing=0)
 Adds images formed in a grid.
 
Sprite clone () const
 Copies all information from this sprite to another, excluding the graphics that remain shared.
 
void draw (Canvas &canvas, const Rectf &dest)
 
void draw (Canvas &canvas, const Rectf &src, const Rectf &dest)
 
void draw (Canvas &canvas, float x, float y)
 Draw sprite on graphic context.
 
void draw (Canvas &canvas, int x, int y)
 
void finish ()
 Finish animation.
 
void get_alignment (Origin &origin, int &x, int &y) const
 Returns translation hot-spot.
 
float get_alpha () const
 Returns current alpha.
 
Angle get_angle () const
 Returns current angle in degrees.
 
Angle get_base_angle () const
 Returns the base angle in degrees - angle added to any rotation set with set_rotate() or rotate().
 
Colorf get_color () const
 Returns current color.
 
int get_current_frame () const
 Returns current frame in animation. 0 is first frame.
 
int get_frame_count () const
 Returns number of frames in animation.
 
int get_frame_delay (int frame) const
 Returns the delay of a frame.
 
Point get_frame_offset (int frame) const
 Returns the translation offset of a frame. 0 is first frame.
 
Size get_frame_size (int frame) const
 Returns the size of a frame. 0 is first frame.
 
Subtexture get_frame_texture (int frame) const
 Return the texture of a frame. 0 is first frame.
 
int get_height () const
 Return the height of the current frame, shortcut for 'get_frame_size(get_current_frame()).height'.
 
int get_id () const
 Returns the attached id (if exists).
 
bool get_linear_filter () const
 Returns true if the sprite uses a linear filter for scaling up and down, false if a nearest-point filter is used.
 
void get_rotation_hotspot (Origin &origin, int &x, int &y) const
 Returns rotation hot-spot.
 
void get_scale (float &x, float &y) const
 Returns scale for x and y.
 
ShowOnFinish get_show_on_finish () const
 Returns an enum for what is shown when the animation is finished.
 
Size get_size () const
 Return the size of the current frame, shortcut for 'get_frame_size(get_current_frame())'.
 
int get_width () const
 Return the width of the current frame, shortcut for 'get_frame_size(get_current_frame()).width'.
 
bool is_finished () const
 Returns true if animation is finished.
 
bool is_looping () const
 Returns true if animation has looped in the last update cycle.
 
bool is_null () const
 Returns true if this object is invalid.
 
bool is_play_backward () const
 Returns true if animation is played in from right to left (starts at end).
 
bool is_play_loop () const
 Returns true if animation is played in loop (more than once).
 
bool is_play_pingpong () const
 Returns true if animation is played in ping-pong mode.
 
 operator bool () const
 
bool operator!= (const Sprite &other) const
 Inequality operator.
 
bool operator< (const Sprite &other) const
 Less than operator.
 
Spriteoperator= (const Sprite &copy)
 Copy assignment operator.
 
bool operator== (const Sprite &other) const
 Equality operator.
 
void restart ()
 Restart animation.
 
void rotate (Angle angle)
 Add angle in degrees to current angle.
 
void rotate_pitch (Angle angle)
 Add angle in degrees to current pitch angle.
 
void rotate_yaw (Angle angle)
 Add angle in degrees to current yaw angle.
 
void set_alignment (Origin origin, int x=0, int y=0)
 Sets translation hotspot.
 
void set_alpha (float alpha)
 Sets transparency.
 
void set_angle (Angle angle)
 Set absolute rotation angle.
 
void set_angle_pitch (Angle angle)
 Set absolute rotation pitch angle.
 
void set_angle_yaw (Angle angle)
 Set absolute rotation yaw angle.
 
void set_base_angle (Angle angle)
 Sets the base angle in degrees - angle added to any rotation set with set_rotate() or rotate().
 
void set_color (const Color &c)
 Set color.
 
void set_color (const Colorf &color)
 Sets the color.
 
void set_delay (int delay_ms)
 Sets the delay for all frames.
 
void set_frame (unsigned int frame)
 Sets current animation frame. 0 is first frame.
 
void set_frame_delay (int frame, int delay_ms)
 Sets the delay of a specific frame.
 
void set_frame_offset (int frame, Point offset)
 Sets the translate offset of a specific frame. 0 is first frame.
 
void set_id (int id)
 Sets an attached id.
 
void set_image_data (const Sprite &image_source)
 Sets the image data from another sprite, sharing animation state.
 
void set_linear_filter (bool linear_filter=true)
 Set to true if a linear filter should be used for scaling up and down, false if a nearest-point filter should be used.
 
void set_play_backward (bool backward=true)
 Set to true if animation should go backward (start at end).
 
void set_play_loop (bool loop=true)
 Set to true if animation should loop, false otherwise.
 
void set_play_pingpong (bool pingpong=true)
 Set to true if animation should loop, false otherwise.
 
void set_rotation_hotspot (Origin origin, int x=0, int y=0)
 Sets rotation hotspot.
 
void set_scale (float x, float y)
 Set scale for x and y directions individually.
 
void set_show_on_finish (Sprite::ShowOnFinish show_on_finish)
 Set what is shown when the animation is finished.
 
Signal< void()> & sig_animation_finished ()
 Sig animation finished.
 
void throw_if_null () const
 Throw an exception if this object is invalid.
 
void update (int time_elapsed_ms)
 Call this function to update the animation.
 

Static Public Member Functions

static Sprite load (Canvas &canvas, const std::string &id, const XMLResourceDocument &doc)
 Loads a Sprite from a XML resource definition.
 
static Resource< Spriteresource (Canvas &canvas, const std::string &id, const ResourceManager &resources)
 Retrieves a Sprite resource from the resource manager.
 

Friends

class FontFamily_Impl
 

Detailed Description

Sprite class.

Member Enumeration Documentation

◆ ShowOnFinish

Enumerator
show_blank 
show_last_frame 
show_first_frame 

Constructor & Destructor Documentation

◆ Sprite() [1/5]

clan::Sprite::Sprite ( )

Constructs a null instance.

◆ Sprite() [2/5]

clan::Sprite::Sprite ( Canvas & canvas,
const std::string & fullname,
const ImageImportDescription & import_desc = ImageImportDescription() )

Constructs a Sprite.

Parameters
canvas= Canvas
fullname= String Ref

◆ Sprite() [3/5]

clan::Sprite::Sprite ( Canvas & canvas,
const std::string & filename,
const FileSystem & file_system,
const ImageImportDescription & import_desc = ImageImportDescription() )

Constructs a Sprite.

Parameters
canvas= Canvas
filename= String Ref
dir= Virtual Directory

◆ Sprite() [4/5]

clan::Sprite::Sprite ( Canvas & canvas,
IODevice & file,
const std::string & image_type,
const ImageImportDescription & import_desc = ImageImportDescription() )

Constructs a Sprite.

Parameters
canvas= Canvas
file= IODevice
image_type= String

◆ Sprite() [5/5]

clan::Sprite::Sprite ( Canvas & canvas)

Constructs an empty Sprite.

Parameters
gc= Graphic Context

◆ ~Sprite()

virtual clan::Sprite::~Sprite ( )
virtual

Member Function Documentation

◆ add_alphaclipped_frames()

void clan::Sprite::add_alphaclipped_frames ( Canvas & canvas,
const Texture2D & texture,
int xpos = 0,
int ypos = 0,
float trans_limit = 0.05f )

Adds images separated with pure alpha (within trans_limit).

The alpha clipper will cut out frames from an image based on the transparency in the picture. It first determines the height of a row by searching for the first line that it considers completely transparent. Then it finds the width of each frame on this line by looking for columns that are completely transparency.

Parameters
pixelbufferImage source.
textureImage source.
xpos,yposUpper left position where alpha cutting should begin.
trans_limitAmount of non-transparent alpha allowed before a pixel is not considered transparent.

◆ add_alphaclipped_frames_free()

void clan::Sprite::add_alphaclipped_frames_free ( Canvas & canvas,
const Texture2D & texture,
int xpos = 0,
int ypos = 0,
float trans_limit = 0.05f )

Adds images separated with pure alpha (within trans_limit).

The alpha clipper will cut out frames from an image based on the transparency in the picture. It scans the lines horizontally from top to bottom. As soon as a non-transarent pixel is discovered, the clipper finds the bounding box for that region and then moves on.

Parameters
pixelbufferImage source.
textureImage source.
xpos,yposUpper left position where alpha cutting should begin.
trans_limitAmount of non-transparent alpha allowed before a pixel is not considered transparent.

◆ add_frame() [1/5]

void clan::Sprite::add_frame ( Canvas & canvas,
const std::string & filename,
const FileSystem & file_system,
const ImageImportDescription & import_desc = ImageImportDescription() )

Add frame.

Parameters
filename= String Ref
dir= Virtual Directory

◆ add_frame() [2/5]

void clan::Sprite::add_frame ( Canvas & canvas,
const std::string & fullname,
const ImageImportDescription & import_desc = ImageImportDescription() )

Add frame.

Parameters
fullname= String Ref

◆ add_frame() [3/5]

void clan::Sprite::add_frame ( Canvas & canvas,
IODevice & file,
const std::string & image_type,
const ImageImportDescription & import_desc = ImageImportDescription() )

Add frame.

Parameters
file= IODevice
image_type= String

◆ add_frame() [4/5]

void clan::Sprite::add_frame ( const Texture2D & texture)

Add frame.

Parameters
texture= Texture

◆ add_frame() [5/5]

void clan::Sprite::add_frame ( const Texture2D & texture,
const Rect & frame )

Add frame.

Parameters
texture= Texture
frame= Rect

◆ add_frames()

void clan::Sprite::add_frames ( const Texture2D & texture,
Rect * frames,
int num_frames )

Add frames.

Parameters
texture= Texture
frames= Rect
num_frames= value

◆ add_gridclipped_frames()

void clan::Sprite::add_gridclipped_frames ( Canvas & canvas,
const Texture2D & texture,
int xpos,
int ypos,
int width,
int height,
int xarray = 1,
int yarray = 1,
int array_skipframes = 0,
int xspacing = 0,
int yspacing = 0 )

Adds images formed in a grid.

This function will cut out a grid of frames from one image.

Parameters
pixelbufferImage source.
textureImage source.
xpos,yposPosition of where image grid starts.
width,heightSize of a frame in the grid.
xarray,yarrayNumber of columns and rows in grid.
array_skipframesNumber of frames to skip at last gridline.
xspacing,yspacingPixel interspacing between grid frames.

◆ clone()

Sprite clan::Sprite::clone ( ) const

Copies all information from this sprite to another, excluding the graphics that remain shared.

◆ draw() [1/4]

void clan::Sprite::draw ( Canvas & canvas,
const Rectf & dest )

◆ draw() [2/4]

void clan::Sprite::draw ( Canvas & canvas,
const Rectf & src,
const Rectf & dest )

◆ draw() [3/4]

void clan::Sprite::draw ( Canvas & canvas,
float x,
float y )

Draw sprite on graphic context.

Parameters
x,yAnchor position of where to render sprite. Actual rendering position depends on the anchor and the alignment mode.
gcGraphic context on which to render upon. If null, will use Display's current graphic context.
srcSource rectangle to draw. Use this is draw only part of the sprite.
destRectangle to draw sprite in.

◆ draw() [4/4]

void clan::Sprite::draw ( Canvas & canvas,
int x,
int y )

◆ finish()

void clan::Sprite::finish ( )

Finish animation.

When an animation is finished, it will no longer show, unless ShowLastFrame is set to anything other than show_blank

◆ get_alignment()

void clan::Sprite::get_alignment ( Origin & origin,
int & x,
int & y ) const

Returns translation hot-spot.

◆ get_alpha()

float clan::Sprite::get_alpha ( ) const

Returns current alpha.

Alpha 0.0f is full transparency, and 1.0f is full visibility (solid).

◆ get_angle()

Angle clan::Sprite::get_angle ( ) const

Returns current angle in degrees.

◆ get_base_angle()

Angle clan::Sprite::get_base_angle ( ) const

Returns the base angle in degrees - angle added to any rotation set with set_rotate() or rotate().

◆ get_color()

Colorf clan::Sprite::get_color ( ) const

Returns current color.

Alpha 0.0f is full transparency, and 1.0f is full visibility (solid).

◆ get_current_frame()

int clan::Sprite::get_current_frame ( ) const

Returns current frame in animation. 0 is first frame.

◆ get_frame_count()

int clan::Sprite::get_frame_count ( ) const

Returns number of frames in animation.

◆ get_frame_delay()

int clan::Sprite::get_frame_delay ( int frame) const

Returns the delay of a frame.

Parameters
frame= The frame. 0 is first frame.
Returns
The delay in milliseconds

◆ get_frame_offset()

Point clan::Sprite::get_frame_offset ( int frame) const

Returns the translation offset of a frame. 0 is first frame.

◆ get_frame_size()

Size clan::Sprite::get_frame_size ( int frame) const

Returns the size of a frame. 0 is first frame.

◆ get_frame_texture()

Subtexture clan::Sprite::get_frame_texture ( int frame) const

Return the texture of a frame. 0 is first frame.

◆ get_height()

int clan::Sprite::get_height ( ) const

Return the height of the current frame, shortcut for 'get_frame_size(get_current_frame()).height'.

◆ get_id()

int clan::Sprite::get_id ( ) const

Returns the attached id (if exists).

◆ get_linear_filter()

bool clan::Sprite::get_linear_filter ( ) const

Returns true if the sprite uses a linear filter for scaling up and down, false if a nearest-point filter is used.

◆ get_rotation_hotspot()

void clan::Sprite::get_rotation_hotspot ( Origin & origin,
int & x,
int & y ) const

Returns rotation hot-spot.

◆ get_scale()

void clan::Sprite::get_scale ( float & x,
float & y ) const

Returns scale for x and y.

1.0f is normal scale, 2.0f is twice the size, etc.

◆ get_show_on_finish()

ShowOnFinish clan::Sprite::get_show_on_finish ( ) const

Returns an enum for what is shown when the animation is finished.

If show_blank is returned, nothing is shown when animation is done.

◆ get_size()

Size clan::Sprite::get_size ( ) const

Return the size of the current frame, shortcut for 'get_frame_size(get_current_frame())'.

◆ get_width()

int clan::Sprite::get_width ( ) const

Return the width of the current frame, shortcut for 'get_frame_size(get_current_frame()).width'.

◆ is_finished()

bool clan::Sprite::is_finished ( ) const

Returns true if animation is finished.

When an animation is finished, it will no longer show, unless ShowLastFrame is set to anything other than show_blank

◆ is_looping()

bool clan::Sprite::is_looping ( ) const

Returns true if animation has looped in the last update cycle.

◆ is_null()

bool clan::Sprite::is_null ( ) const
inline

Returns true if this object is invalid.

◆ is_play_backward()

bool clan::Sprite::is_play_backward ( ) const

Returns true if animation is played in from right to left (starts at end).

◆ is_play_loop()

bool clan::Sprite::is_play_loop ( ) const

Returns true if animation is played in loop (more than once).

◆ is_play_pingpong()

bool clan::Sprite::is_play_pingpong ( ) const

Returns true if animation is played in ping-pong mode.

◆ load()

static Sprite clan::Sprite::load ( Canvas & canvas,
const std::string & id,
const XMLResourceDocument & doc )
static

Loads a Sprite from a XML resource definition.

◆ operator bool()

clan::Sprite::operator bool ( ) const
inlineexplicit

◆ operator!=()

bool clan::Sprite::operator!= ( const Sprite & other) const
inline

Inequality operator.

◆ operator<()

bool clan::Sprite::operator< ( const Sprite & other) const
inline

Less than operator.

◆ operator=()

Sprite & clan::Sprite::operator= ( const Sprite & copy)

Copy assignment operator.

◆ operator==()

bool clan::Sprite::operator== ( const Sprite & other) const
inline

Equality operator.

◆ resource()

static Resource< Sprite > clan::Sprite::resource ( Canvas & canvas,
const std::string & id,
const ResourceManager & resources )
static

Retrieves a Sprite resource from the resource manager.

Parameters
gc= canvas = Canvas
resources= Resource manager
id= id

◆ restart()

void clan::Sprite::restart ( )

Restart animation.

◆ rotate()

void clan::Sprite::rotate ( Angle angle)

Add angle in degrees to current angle.

◆ rotate_pitch()

void clan::Sprite::rotate_pitch ( Angle angle)

Add angle in degrees to current pitch angle.

◆ rotate_yaw()

void clan::Sprite::rotate_yaw ( Angle angle)

Add angle in degrees to current yaw angle.

◆ set_alignment()

void clan::Sprite::set_alignment ( Origin origin,
int x = 0,
int y = 0 )

Sets translation hotspot.

◆ set_alpha()

void clan::Sprite::set_alpha ( float alpha)

Sets transparency.

Alpha 0.0f is full transparency, and 1.0f is full visibility (solid).

◆ set_angle()

void clan::Sprite::set_angle ( Angle angle)

Set absolute rotation angle.

◆ set_angle_pitch()

void clan::Sprite::set_angle_pitch ( Angle angle)

Set absolute rotation pitch angle.

◆ set_angle_yaw()

void clan::Sprite::set_angle_yaw ( Angle angle)

Set absolute rotation yaw angle.

◆ set_base_angle()

void clan::Sprite::set_base_angle ( Angle angle)

Sets the base angle in degrees - angle added to any rotation set with set_rotate() or rotate().

◆ set_color() [1/2]

void clan::Sprite::set_color ( const Color & c)
inline

Set color.

Parameters
c= Color

References clan::c, clan::color, clan::Vec4< Type >::r, and set_color().

Referenced by set_color().

◆ set_color() [2/2]

void clan::Sprite::set_color ( const Colorf & color)

Sets the color.

Alpha 0.0f is full transparency, and 1.0f is full visibility (solid).

◆ set_delay()

void clan::Sprite::set_delay ( int delay_ms)

Sets the delay for all frames.

Parameters
delay_ms= Delay in milliseconds

◆ set_frame()

void clan::Sprite::set_frame ( unsigned int frame)

Sets current animation frame. 0 is first frame.

It will cap to available range.

◆ set_frame_delay()

void clan::Sprite::set_frame_delay ( int frame,
int delay_ms )

Sets the delay of a specific frame.

Parameters
frame= Frame number. 0 is first frame.
delay_ms= Delay in milliseconds

◆ set_frame_offset()

void clan::Sprite::set_frame_offset ( int frame,
Point offset )

Sets the translate offset of a specific frame. 0 is first frame.

◆ set_id()

void clan::Sprite::set_id ( int id)

Sets an attached id.

◆ set_image_data()

void clan::Sprite::set_image_data ( const Sprite & image_source)

Sets the image data from another sprite, sharing animation state.

Use this to change the look of your sprite.

◆ set_linear_filter()

void clan::Sprite::set_linear_filter ( bool linear_filter = true)

Set to true if a linear filter should be used for scaling up and down, false if a nearest-point filter should be used.

◆ set_play_backward()

void clan::Sprite::set_play_backward ( bool backward = true)

Set to true if animation should go backward (start at end).

◆ set_play_loop()

void clan::Sprite::set_play_loop ( bool loop = true)

Set to true if animation should loop, false otherwise.

◆ set_play_pingpong()

void clan::Sprite::set_play_pingpong ( bool pingpong = true)

Set to true if animation should loop, false otherwise.

◆ set_rotation_hotspot()

void clan::Sprite::set_rotation_hotspot ( Origin origin,
int x = 0,
int y = 0 )

Sets rotation hotspot.

◆ set_scale()

void clan::Sprite::set_scale ( float x,
float y )

Set scale for x and y directions individually.

1.0f is normal scale, 2.0f is twice the size, etc.

◆ set_show_on_finish()

void clan::Sprite::set_show_on_finish ( Sprite::ShowOnFinish show_on_finish)

Set what is shown when the animation is finished.

◆ sig_animation_finished()

Signal< void()> & clan::Sprite::sig_animation_finished ( )

Sig animation finished.

Returns
Signal<void()>

◆ throw_if_null()

void clan::Sprite::throw_if_null ( ) const

Throw an exception if this object is invalid.

◆ update()

void clan::Sprite::update ( int time_elapsed_ms)

Call this function to update the animation.

Parameters
time_elapsed_ms= Time elapsed in milliseconds.

Friends And Related Symbol Documentation

◆ FontFamily_Impl

friend class FontFamily_Impl
friend

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