#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... | |
Sprite & | operator= (const Sprite ©) |
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< Sprite > | resource (Canvas &canvas, const std::string &id, const ResourceManager &resources) |
Retrieves a Sprite resource from the resource manager. More... | |
Friends | |
class | FontFamily_Impl |
Sprite class.
clan::Sprite::Sprite | ( | ) |
Constructs a null instance.
clan::Sprite::Sprite | ( | Canvas & | canvas, |
const std::string & | fullname, | ||
const ImageImportDescription & | import_desc = ImageImportDescription() |
||
) |
clan::Sprite::Sprite | ( | Canvas & | canvas, |
const std::string & | filename, | ||
const FileSystem & | file_system, | ||
const ImageImportDescription & | import_desc = ImageImportDescription() |
||
) |
clan::Sprite::Sprite | ( | Canvas & | canvas, |
IODevice & | file, | ||
const std::string & | image_type, | ||
const ImageImportDescription & | import_desc = ImageImportDescription() |
||
) |
|
virtual |
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.
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.
void clan::Sprite::add_frame | ( | Canvas & | canvas, |
const std::string & | fullname, | ||
const ImageImportDescription & | import_desc = ImageImportDescription() |
||
) |
Add frame.
fullname | = String Ref |
void clan::Sprite::add_frame | ( | Canvas & | canvas, |
IODevice & | file, | ||
const std::string & | image_type, | ||
const ImageImportDescription & | import_desc = ImageImportDescription() |
||
) |
Add frame.
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.
filename | = String Ref |
dir | = Virtual Directory |
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.
pixelbuffer | Image source. |
texture | Image source. |
xpos,ypos | Position of where image grid starts. |
width,height | Size of a frame in the grid. |
xarray,yarray | Number of columns and rows in grid. |
array_skipframes | Number of frames to skip at last gridline. |
xspacing,yspacing | Pixel 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.
x,y | Anchor position of where to render sprite. Actual rendering position depends on the anchor and the alignment mode. |
gc | Graphic context on which to render upon. If null, will use Display's current graphic context. |
src | Source rectangle to draw. Use this is draw only part of the sprite. |
dest | Rectangle to draw sprite in. |
void clan::Sprite::draw | ( | Canvas & | canvas, |
int | x, | ||
int | y | ||
) |
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.
frame | = The frame. 0 is first frame. |
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.
|
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 |
Loads a Sprite from a XML resource definition.
|
inlineexplicit |
|
inline |
Inequality operator.
|
inline |
Less than operator.
|
inline |
Equality operator.
|
static |
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).
|
inline |
Set color.
c | = Color |
References clan::c, clan::color, and set_color().
Referenced by set_color().
void clan::Sprite::set_delay | ( | int | delay_ms | ) |
Sets the delay for all frames.
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.
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.
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.
time_elapsed_ms | = Time elapsed in milliseconds. |
|
friend |