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

Static Public Member Functions

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

Friends

class FontFamily_Impl
 

Detailed Description

Sprite class.

Constructor & Destructor Documentation

clan::Sprite::Sprite ( )

Constructs a null instance.

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

Constructs a Sprite.

Parameters
canvas= Canvas
fullname= String Ref
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
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
clan::Sprite::Sprite ( Canvas canvas)

Constructs an empty Sprite.

Parameters
gc= Graphic Context
virtual clan::Sprite::~Sprite ( )
virtual

Member Function Documentation

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.
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.
void clan::Sprite::add_frame ( const Texture2D texture)

Add frame.

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

Add frame.

Parameters
fullname= String Ref
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
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
void clan::Sprite::add_frame ( const Texture2D texture,
const Rect frame 
)

Add frame.

Parameters
texture= Texture
frame= Rect
void clan::Sprite::add_frames ( const Texture2D texture,
Rect frames,
int  num_frames 
)

Add frames.

Parameters
texture= Texture
frames= Rect
num_frames= value
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.
Sprite clan::Sprite::clone ( ) const

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

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.
void clan::Sprite::draw ( Canvas canvas,
int  x,
int  y 
)
void clan::Sprite::draw ( Canvas canvas,
const Rectf src,
const Rectf dest 
)
void clan::Sprite::draw ( Canvas canvas,
const Rectf dest 
)
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

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

Returns translation hot-spot.

float clan::Sprite::get_alpha ( ) const

Returns current alpha.

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

Angle clan::Sprite::get_angle ( ) const

Returns current angle in degrees.

Angle clan::Sprite::get_base_angle ( ) const

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

Colorf clan::Sprite::get_color ( ) const

Returns current color.

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

int clan::Sprite::get_current_frame ( ) const

Returns current frame in animation. 0 is first frame.

int clan::Sprite::get_frame_count ( ) const

Returns number of frames in animation.

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
Point clan::Sprite::get_frame_offset ( int  frame) const

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

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

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

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

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

int clan::Sprite::get_height ( ) const

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

int clan::Sprite::get_id ( ) const

Returns the attached id (if exists).

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.

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

Returns rotation hot-spot.

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.

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.

Size clan::Sprite::get_size ( ) const

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

int clan::Sprite::get_width ( ) const

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

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

bool clan::Sprite::is_looping ( ) const

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

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

Returns true if this object is invalid.

bool clan::Sprite::is_play_backward ( ) const

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

bool clan::Sprite::is_play_loop ( ) const

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

bool clan::Sprite::is_play_pingpong ( ) const

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

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

Loads a Sprite from a XML resource definition.

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

Inequality operator.

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

Less than operator.

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

Copy assignment operator.

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

Equality operator.

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
void clan::Sprite::restart ( )

Restart animation.

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

Add angle in degrees to current angle.

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

Add angle in degrees to current pitch angle.

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

Add angle in degrees to current yaw angle.

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

Sets translation hotspot.

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

Sets transparency.

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

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

Set absolute rotation angle.

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

Set absolute rotation pitch angle.

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

Set absolute rotation yaw 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().

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

Sets the color.

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

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

Sets the delay for all frames.

Parameters
delay_ms= Delay in milliseconds
void clan::Sprite::set_frame ( unsigned int  frame)

Sets current animation frame. 0 is first frame.

It will cap to available range.

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
void clan::Sprite::set_frame_offset ( int  frame,
Point  offset 
)

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

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

Sets an attached id.

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.

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.

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

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

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

Set to true if animation should loop, false otherwise.

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

Set to true if animation should loop, false otherwise.

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

Sets rotation hotspot.

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.

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

Set what is shown when the animation is finished.

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

Sig animation finished.

Returns
Signal<void()>
void clan::Sprite::throw_if_null ( ) const

Throw an exception if this object is invalid.

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 Function Documentation

friend class FontFamily_Impl
friend

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