ClanLib
2.3.7
|
Sprite class. More...
#include <sprite.h>
Public Types | |
Enums | |
enum | ShowOnFinish { show_blank, show_last_frame, show_first_frame } |
Public Member Functions | |
Construction | |
CL_Sprite () | |
Constructs a null instance. More... | |
CL_Sprite (CL_GraphicContext &gc, const CL_StringRef &fullname, const CL_ImageImportDescription &import_desc=CL_ImageImportDescription()) | |
Constructs a Sprite. More... | |
CL_Sprite (CL_GraphicContext &gc, const CL_StringRef &filename, CL_VirtualDirectory &dir, const CL_ImageImportDescription &import_desc=CL_ImageImportDescription()) | |
Constructs a Sprite. More... | |
CL_Sprite (CL_GraphicContext &gc, const CL_StringRef &resource_id, CL_ResourceManager *resources, const CL_ImageImportDescription &import_desc=CL_ImageImportDescription()) | |
Constructs a Sprite. More... | |
CL_Sprite (CL_GraphicContext &gc, CL_IODevice &file, const CL_String &image_type, const CL_ImageImportDescription &import_desc=CL_ImageImportDescription()) | |
Constructs a Sprite. More... | |
CL_Sprite (CL_GraphicContext &gc, const CL_SpriteDescription &description) | |
Constructs a Sprite. More... | |
virtual | ~CL_Sprite () |
Attributes | |
bool | is_null () const |
Returns true if this object is invalid. More... | |
void | throw_if_null () const |
Throw an exception if this object is invalid. More... | |
CL_Angle | get_angle () const |
Returns current angle in degrees. More... | |
CL_Angle | get_base_angle () const |
Returns the base angle in degrees - angle added to any rotation set with set_rotate() or rotate(). More... | |
void | get_scale (float &x, float &y) const |
Returns scale for x and y. More... | |
float | get_alpha () const |
Returns current alpha. More... | |
CL_Colorf | get_color () const |
Returns current color. 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_alignment (CL_Origin &origin, int &x, int &y) const |
Returns translation hot-spot. More... | |
void | get_rotation_hotspot (CL_Origin &origin, int &x, int &y) const |
Returns rotation hot-spot. 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... | |
CL_Point | get_frame_offset (int frame) const |
Returns the translation offset of a frame. 0 is first frame. More... | |
CL_Size | get_frame_size (int frame) const |
Returns the size of a frame. 0 is first frame. More... | |
int | get_width () const |
Return the width of the current frame, shortcut for 'get_frame_size(get_current_frame()).width'. More... | |
int | get_height () const |
Return the height of the current frame, shortcut for 'get_frame_size(get_current_frame()).height'. More... | |
CL_Size | get_size () const |
Return the size of the current frame, shortcut for 'get_frame_size(get_current_frame())'. More... | |
int | get_id () const |
Returns the attached id (if exists). More... | |
bool | is_play_loop () const |
Returns true if animation is played in loop (more than once). More... | |
bool | is_play_backward () const |
Returns true if animation is played in from right to left (starts at end). More... | |
bool | is_play_pingpong () const |
Returns true if animation is played in ping-pong mode. More... | |
ShowOnFinish | get_show_on_finish () const |
Returns an enum for what is shown when the animation is finished. 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... | |
Operators | |
bool | operator== (const CL_Sprite &other) const |
Equality operator. More... | |
bool | operator!= (const CL_Sprite &other) const |
Inequality operator. More... | |
bool | operator< (const CL_Sprite &other) const |
Less than operator. More... | |
Operations | |
CL_Sprite & | operator= (const CL_Sprite ©) |
Copy assignment operator. More... | |
void | set_image_data (const CL_Sprite &image_source) |
Sets the image data from another sprite, sharing animation state. More... | |
void | clone (const CL_Sprite &source) |
Copies all information from another sprite into this, not sharing animation state. More... | |
void | draw (CL_GraphicContext &gc, float x, float y) |
Draw sprite on graphic context. More... | |
void | draw (CL_GraphicContext &gc, int x, int y) |
void | draw (CL_GraphicContext &gc, const CL_Rectf &src, const CL_Rectf &dest) |
void | draw (CL_GraphicContext &gc, const CL_Rectf &dest) |
int | update (int time_elapsed_ms=-1) |
Call this function to update the animation. More... | |
void | set_angle (CL_Angle angle) |
Set absolute rotation angle. More... | |
void | set_angle_pitch (CL_Angle angle) |
Set absolute rotation pitch angle. More... | |
void | set_angle_yaw (CL_Angle angle) |
Set absolute rotation yaw angle. More... | |
void | rotate (CL_Angle angle) |
Add angle in degrees to current angle. More... | |
void | rotate_pitch (CL_Angle angle) |
Add angle in degrees to current pitch angle. More... | |
void | rotate_yaw (CL_Angle angle) |
Add angle in degrees to current yaw angle. More... | |
void | set_base_angle (CL_Angle angle) |
Sets the base angle in degrees - angle added to any rotation set with set_rotate() or rotate(). More... | |
void | set_scale (float x, float y) |
Set scale for x and y directions individually. More... | |
void | set_alpha (float alpha) |
Sets transparency. More... | |
void | set_color (const CL_Colorf &color) |
Sets the color. More... | |
void | set_color (const CL_Color &c) |
Set color. 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_alignment (CL_Origin origin, int x=0, int y=0) |
Sets translation hotspot. More... | |
void | set_rotation_hotspot (CL_Origin origin, int x=0, int y=0) |
Sets rotation hotspot. More... | |
void | set_frame (unsigned int frame) |
Sets current animation frame. 0 is first frame. More... | |
void | set_delay (int delay_ms) |
Sets the delay for all frames. More... | |
void | set_frame_delay (int frame, int delay_ms) |
Sets the delay of a specific frame. More... | |
void | set_frame_offset (int frame, CL_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 | finish () |
Finish animation. More... | |
void | restart () |
Restart animation. 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_play_backward (bool backward=true) |
Set to true if animation should go backward (start at end). More... | |
void | set_show_on_finish (CL_Sprite::ShowOnFinish show_on_finish) |
Set what is shown when the animation is finished. More... | |
Signals | |
CL_Signal_v0 & | sig_animation_finished () |
Sig animation finished. More... | |
Sprite class.
CL_Sprite::CL_Sprite | ( | ) |
Constructs a null instance.
CL_Sprite::CL_Sprite | ( | CL_GraphicContext & | gc, |
const CL_StringRef & | fullname, | ||
const CL_ImageImportDescription & | import_desc = CL_ImageImportDescription() |
||
) |
Constructs a Sprite.
gc | = Graphic Context |
fullname | = String Ref |
CL_Sprite::CL_Sprite | ( | CL_GraphicContext & | gc, |
const CL_StringRef & | filename, | ||
CL_VirtualDirectory & | dir, | ||
const CL_ImageImportDescription & | import_desc = CL_ImageImportDescription() |
||
) |
Constructs a Sprite.
gc | = Graphic Context |
filename | = String Ref |
dir | = Virtual Directory |
CL_Sprite::CL_Sprite | ( | CL_GraphicContext & | gc, |
const CL_StringRef & | resource_id, | ||
CL_ResourceManager * | resources, | ||
const CL_ImageImportDescription & | import_desc = CL_ImageImportDescription() |
||
) |
Constructs a Sprite.
gc | = Graphic Context |
resource_id | = String Ref |
resources | = Resource Manager |
CL_Sprite::CL_Sprite | ( | CL_GraphicContext & | gc, |
CL_IODevice & | file, | ||
const CL_String & | image_type, | ||
const CL_ImageImportDescription & | import_desc = CL_ImageImportDescription() |
||
) |
Constructs a Sprite.
gc | = Graphic Context |
file | = IODevice |
image_type | = String |
CL_Sprite::CL_Sprite | ( | CL_GraphicContext & | gc, |
const CL_SpriteDescription & | description | ||
) |
Constructs a Sprite.
gc | = Graphic Context |
description | = Sprite Description |
|
virtual |
void CL_Sprite::clone | ( | const CL_Sprite & | source) |
Copies all information from another sprite into this, not sharing animation state.
This will not share animation state afterwards, like sprite1 = sprite2 would do.
void CL_Sprite::draw | ( | CL_GraphicContext & | gc, |
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 CL_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 CL_Sprite::draw | ( | CL_GraphicContext & | gc, |
int | x, | ||
int | y | ||
) |
void CL_Sprite::draw | ( | CL_GraphicContext & | gc, |
const CL_Rectf & | src, | ||
const CL_Rectf & | dest | ||
) |
void CL_Sprite::draw | ( | CL_GraphicContext & | gc, |
const CL_Rectf & | dest | ||
) |
void CL_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 CL_Sprite::get_alignment | ( | CL_Origin & | origin, |
int & | x, | ||
int & | y | ||
) | const |
Returns translation hot-spot.
float CL_Sprite::get_alpha | ( | ) | const |
Returns current alpha.
Alpha 0.0f is full transparency, and 1.0f is full visibility (solid).
CL_Angle CL_Sprite::get_angle | ( | ) | const |
Returns current angle in degrees.
CL_Angle CL_Sprite::get_base_angle | ( | ) | const |
Returns the base angle in degrees - angle added to any rotation set with set_rotate() or rotate().
CL_Colorf CL_Sprite::get_color | ( | ) | const |
Returns current color.
Alpha 0.0f is full transparency, and 1.0f is full visibility (solid).
int CL_Sprite::get_current_frame | ( | ) | const |
Returns current frame in animation. 0 is first frame.
int CL_Sprite::get_frame_count | ( | ) | const |
Returns number of frames in animation.
int CL_Sprite::get_frame_delay | ( | int | frame) | const |
Returns the delay of a frame.
frame | = The frame. 0 is first frame. |
CL_Point CL_Sprite::get_frame_offset | ( | int | frame) | const |
Returns the translation offset of a frame. 0 is first frame.
CL_Size CL_Sprite::get_frame_size | ( | int | frame) | const |
Returns the size of a frame. 0 is first frame.
int CL_Sprite::get_height | ( | ) | const |
Return the height of the current frame, shortcut for 'get_frame_size(get_current_frame()).height'.
int CL_Sprite::get_id | ( | ) | const |
Returns the attached id (if exists).
bool CL_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 CL_Sprite::get_rotation_hotspot | ( | CL_Origin & | origin, |
int & | x, | ||
int & | y | ||
) | const |
Returns rotation hot-spot.
void CL_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 CL_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.
CL_Size CL_Sprite::get_size | ( | ) | const |
Return the size of the current frame, shortcut for 'get_frame_size(get_current_frame())'.
int CL_Sprite::get_width | ( | ) | const |
Return the width of the current frame, shortcut for 'get_frame_size(get_current_frame()).width'.
bool CL_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 CL_Sprite::is_looping | ( | ) | const |
Returns true if animation has looped in the last update cycle.
|
inline |
Returns true if this object is invalid.
bool CL_Sprite::is_play_backward | ( | ) | const |
Returns true if animation is played in from right to left (starts at end).
bool CL_Sprite::is_play_loop | ( | ) | const |
Returns true if animation is played in loop (more than once).
bool CL_Sprite::is_play_pingpong | ( | ) | const |
Returns true if animation is played in ping-pong mode.
|
inline |
Inequality operator.
|
inline |
Less than operator.
|
inline |
Equality operator.
void CL_Sprite::restart | ( | ) |
Restart animation.
void CL_Sprite::rotate | ( | CL_Angle | angle) |
Add angle in degrees to current angle.
void CL_Sprite::rotate_pitch | ( | CL_Angle | angle) |
Add angle in degrees to current pitch angle.
void CL_Sprite::rotate_yaw | ( | CL_Angle | angle) |
Add angle in degrees to current yaw angle.
void CL_Sprite::set_alignment | ( | CL_Origin | origin, |
int | x = 0 , |
||
int | y = 0 |
||
) |
Sets translation hotspot.
void CL_Sprite::set_alpha | ( | float | alpha) |
Sets transparency.
Alpha 0.0f is full transparency, and 1.0f is full visibility (solid).
void CL_Sprite::set_angle | ( | CL_Angle | angle) |
Set absolute rotation angle.
void CL_Sprite::set_angle_pitch | ( | CL_Angle | angle) |
Set absolute rotation pitch angle.
void CL_Sprite::set_angle_yaw | ( | CL_Angle | angle) |
Set absolute rotation yaw angle.
void CL_Sprite::set_base_angle | ( | CL_Angle | angle) |
Sets the base angle in degrees - angle added to any rotation set with set_rotate() or rotate().
void CL_Sprite::set_color | ( | const CL_Colorf & | color) |
Sets the color.
Alpha 0.0f is full transparency, and 1.0f is full visibility (solid).
|
inline |
Set color.
c | = Color |
References CL_Colorf::a, CL_Colorf::b, CL_Colorf::g, CL_Color::get_alpha(), CL_Color::get_blue(), CL_Color::get_green(), CL_Color::get_red(), CL_Colorf::r, and set_color().
Referenced by set_color().
void CL_Sprite::set_delay | ( | int | delay_ms) |
Sets the delay for all frames.
delay_ms | = Delay in milliseconds |
void CL_Sprite::set_frame | ( | unsigned int | frame) |
Sets current animation frame. 0 is first frame.
It will cap to available range.
void CL_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 CL_Sprite::set_frame_offset | ( | int | frame, |
CL_Point | offset | ||
) |
Sets the translate offset of a specific frame. 0 is first frame.
void CL_Sprite::set_id | ( | int | id) |
Sets an attached id.
void CL_Sprite::set_image_data | ( | const CL_Sprite & | image_source) |
Sets the image data from another sprite, sharing animation state.
Use this to change the look of your sprite.
void CL_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 CL_Sprite::set_play_backward | ( | bool | backward = true ) |
Set to true if animation should go backward (start at end).
void CL_Sprite::set_play_loop | ( | bool | loop = true ) |
Set to true if animation should loop, false otherwise.
void CL_Sprite::set_play_pingpong | ( | bool | pingpong = true ) |
Set to true if animation should loop, false otherwise.
void CL_Sprite::set_rotation_hotspot | ( | CL_Origin | origin, |
int | x = 0 , |
||
int | y = 0 |
||
) |
Sets rotation hotspot.
void CL_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 CL_Sprite::set_show_on_finish | ( | CL_Sprite::ShowOnFinish | show_on_finish) |
Set what is shown when the animation is finished.
CL_Signal_v0& CL_Sprite::sig_animation_finished | ( | ) |
Sig animation finished.
void CL_Sprite::throw_if_null | ( | ) | const |
Throw an exception if this object is invalid.
int CL_Sprite::update | ( | int | time_elapsed_ms = -1 ) |
Call this function to update the animation.
time_elapsed_ms | = Time elapsed in milliseconds. Use -1 for automatic time calculation |