CL_Sprite Class Reference
[clanDisplay 2D]

Sprite class. More...

#include <sprite.h>

List of all members.

Public Types

Enums

enum  ShowOnFinish { show_blank, show_last_frame, show_first_frame }

Public Member Functions

Construction

 CL_Sprite ()
 Constructs a null instance.
 CL_Sprite (CL_GraphicContext &gc, const CL_StringRef &fullname, const CL_ImageImportDescription &import_desc=CL_ImageImportDescription())
 Constructs a Sprite.
 CL_Sprite (CL_GraphicContext &gc, const CL_StringRef &filename, CL_VirtualDirectory &dir, const CL_ImageImportDescription &import_desc=CL_ImageImportDescription())
 Constructs a Sprite.
 CL_Sprite (CL_GraphicContext &gc, const CL_StringRef &resource_id, CL_ResourceManager *resources, const CL_ImageImportDescription &import_desc=CL_ImageImportDescription())
 Constructs a Sprite.
 CL_Sprite (CL_GraphicContext &gc, CL_IODevice &file, const CL_String &image_type, const CL_ImageImportDescription &import_desc=CL_ImageImportDescription())
 Constructs a Sprite.
 CL_Sprite (CL_GraphicContext &gc, const CL_SpriteDescription &description)
 Constructs a Sprite.
virtual ~CL_Sprite ()
Attributes

bool is_null () const
 Returns true if this object is invalid.
void throw_if_null () const
 Throw an exception if this object is invalid.
CL_Angle get_angle () const
 Returns current angle in degrees.
CL_Angle get_base_angle () const
 Returns the base angle in degrees - angle added to any rotation set with set_rotate() or rotate().
void get_scale (float &x, float &y) const
 Returns scale for x and y.
float get_alpha () const
 Returns current alpha.
CL_Colorf get_color () const
 Returns current color.
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_alignment (CL_Origin &origin, int &x, int &y) const
 Returns translation hot-spot.
void get_rotation_hotspot (CL_Origin &origin, int &x, int &y) const
 Returns rotation hot-spot.
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.
CL_Point get_frame_offset (int frame) const
 Returns the translation offset of a frame. 0 is first frame.
CL_Size get_frame_size (int frame) const
 Returns the size of a frame. 0 is first frame.
int get_width () const
 Return the width of the current frame, shortcut for 'get_frame_size(get_current_frame()).width'.
int get_height () const
 Return the height of the current frame, shortcut for 'get_frame_size(get_current_frame()).height'.
CL_Size get_size () const
 Return the size of the current frame, shortcut for 'get_frame_size(get_current_frame())'.
int get_id () const
 Returns the attached id (if exists).
bool is_play_loop () const
 Returns true if animation is played in loop (more than once).
bool is_play_backward () const
 Returns true if animation is played in from right to left (starts at end).
bool is_play_pingpong () const
 Returns true if animation is played in ping-pong mode.
ShowOnFinish get_show_on_finish () const
 Returns an enum for what is shown when the animation is finished.
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.
Operators

bool operator== (const CL_Sprite &other) const
 Equality operator.
bool operator!= (const CL_Sprite &other) const
 Inequality operator.
bool operator< (const CL_Sprite &other) const
 Less than operator.
Operations

CL_Spriteoperator= (const CL_Sprite &copy)
 Copy assignment operator.
void set_image_data (const CL_Sprite &image_source)
 Sets the image data from another sprite, sharing animation state.
void clone (const CL_Sprite &source)
 Copies all information from another sprite into this, not sharing animation state.
void draw (CL_GraphicContext &gc, float x, float y)
 Draw sprite on graphic context.
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.
void set_angle (CL_Angle angle)
 Set absolute rotation angle.
void set_angle_pitch (CL_Angle angle)
 Set absolute rotation pitch angle.
void set_angle_yaw (CL_Angle angle)
 Set absolute rotation yaw angle.
void rotate (CL_Angle angle)
 Add angle in degrees to current angle.
void rotate_pitch (CL_Angle angle)
 Add angle in degrees to current pitch angle.
void rotate_yaw (CL_Angle angle)
 Add angle in degrees to current yaw angle.
void set_base_angle (CL_Angle angle)
 Sets the base angle in degrees - angle added to any rotation set with set_rotate() or rotate().
void set_scale (float x, float y)
 Set scale for x and y directions individually.
void set_alpha (float alpha)
 Sets transparency.
void set_color (const CL_Colorf &color)
 Sets the color.
void set_color (const CL_Color &c)
 Set color.
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_alignment (CL_Origin origin, int x=0, int y=0)
 Sets translation hotspot.
void set_rotation_hotspot (CL_Origin origin, int x=0, int y=0)
 Sets rotation hotspot.
void set_frame (unsigned int frame)
 Sets current animation frame. 0 is first frame.
void set_delay (int delay_ms)
 Sets the delay for all frames.
void set_frame_delay (int frame, int delay_ms)
 Sets the delay of a specific frame.
void set_frame_offset (int frame, CL_Point offset)
 Sets the translate offset of a specific frame. 0 is first frame.
void set_id (int id)
 Sets an attached id.
void finish ()
 Finish animation.
void restart ()
 Restart animation.
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_play_backward (bool backward=true)
 Set to true if animation should go backward (start at end).
void set_show_on_finish (CL_Sprite::ShowOnFinish show_on_finish)
 Set what is shown when the animation is finished.
Signals

CL_Signal_v0sig_animation_finished ()
 Sig animation finished.

Detailed Description

Sprite class.


Member Enumeration Documentation

Enumerator:
show_blank 
show_last_frame 
show_first_frame 

Constructor & Destructor Documentation

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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
gc = Graphic Context
file = IODevice
image_type = String
CL_Sprite::CL_Sprite ( CL_GraphicContext gc,
const CL_SpriteDescription description 
)

Constructs a Sprite.

Parameters:
gc = Graphic Context
description = Sprite Description
virtual CL_Sprite::~CL_Sprite (  )  [virtual]

Member Function Documentation

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.

Parameters:
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.

Parameters:
frame = The frame. 0 is first frame.
Returns:
The delay in milliseconds
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.

bool CL_Sprite::is_null (  )  const [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.

bool CL_Sprite::operator!= ( const CL_Sprite other  )  const [inline]

Inequality operator.

bool CL_Sprite::operator< ( const CL_Sprite other  )  const [inline]

Less than operator.

CL_Sprite& CL_Sprite::operator= ( const CL_Sprite copy  ) 

Copy assignment operator.

bool CL_Sprite::operator== ( const CL_Sprite other  )  const [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_Color c  )  [inline]
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).

void CL_Sprite::set_delay ( int  delay_ms  ) 

Sets the delay for all frames.

Parameters:
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.

Parameters:
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.

Returns:
Signal_v0
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.

Parameters:
time_elapsed_ms = Time elapsed in milliseconds. Use -1 for automatic time calculation
Returns:
time_elapsed milliseconds since last update

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