Public Member Functions | Friends

animation Class Reference

Class that handles animated elements, their update and their playback. More...

#include <animation.h>

Inheritance diagram for animation:
Inheritance graph
[legend]
Collaboration diagram for animation:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 animation ()
 Default constructor.
 ~animation ()
 Destructor.
void clear ()
 Clears an animation, that is put it back into the original (constructor) state.
animationoperator= (const animation &src)
 Animation copy (similar to copy ()).
void copy (const animation &src)
 Synonym of operator = to guarantee its access from Python.
Playback control methods.

void play ()
 Starts the playback of the animation.
void stop ()
 Stops the playback of the animation.
play_state playstate () const
 Returns whether the animation is currently being played.
void rewind ()
 Rewinds the animation to it's beginning.
void next_frame ()
 Directly jumps to the next frame.
State updating Methods.

bool update ()
 Updates the animation state.
Drawing Methods.

void draw (s_int16 x, s_int16 y, const drawing_area *da_opt=NULL, surface *target=NULL) const
 Draw the object on the screen.
Saving/Loading Methods.

Note:
There is no way to save animations with this class.
s_int8 get (igzstream &file)
 Loads an animation from an opened file.
s_int8 load (string fname)
 Loads an animation from it's filename.
s_int8 put (ogzstream &file) const
 Saves an animation into an opened file, in game format, with alpha and mask values.
s_int8 save (string fname) const
 Saves an animation into an file, in game format, with alpha and mask values.
Global animation properties Methods.

u_int16 nbr_of_frames () const
 Returns the number of frames in this animation.
u_int16 nbr_of_images () const
 Returns the number of images in this animation.
u_int16 currentframe () const
 Returns the index of the currently displayed frame.
void set_currentframe (u_int16 framenbr)
 Sets the current frame.
s_int16 xoffset () const
 Returns the global X offset of the animation.
s_int16 yoffset () const
 Returns the global Y offset of the animation.
void set_offset (s_int16 x, s_int16 y)
 Set the global offsets of this animation.
Image and Animationframe control Methods.

animationframeget_frame (u_int16 nbr)
 Returns a pointer to a desired frame.
imageget_image (u_int16 nbr)
 Returns a pointer to a desired image.
s_int8 insert_image (const image *im, u_int16 pos)
 Inserts an image at a given position of the image array.
s_int8 insert_frame (const animationframe af, u_int16 pos)
 Inserts a frame at a given position of the animationframe array.
s_int8 delete_image (u_int16 pos)
 Removes an image at a given position.
s_int8 delete_frame (u_int16 pos)
 Removes a frame at a given position.
Special FX methods.

void zoom (u_int16 sx, u_int16 sy, const animation *src)
 Zooms an animation.

Friends

class win_anim

Detailed Description

Class that handles animated elements, their update and their playback.

Most often, you will want your drawn objects to be animated. Then you'll probably want to use this class. An animation contains:

During playback, the animation look at the first animation_frame. Each animation_frame refers to an image of the animation, and give it special mask and alpha parameters, as well as a position offset. It also have a delay parameter, telling how many game cycles this frame should stay. Once the delay expired, the animation jumps to the next frame, which is pointed by the current frame. That way, you can easily performs loops or others effects. Each image, as well as each animation_frame, can be accessed individually, thought you'd better try to avoid as much as possible to mess with that.

Definition at line 308 of file animation.h.


Constructor & Destructor Documentation

animation::animation (  ) 

Default constructor.

Definition at line 97 of file animation.cc.

animation::~animation (  ) 

Destructor.

Definition at line 118 of file animation.cc.


Member Function Documentation

void animation::clear (  ) 

Clears an animation, that is put it back into the original (constructor) state.

Definition at line 102 of file animation.cc.

void animation::play (  )  [inline]

Starts the playback of the animation.

Definition at line 344 of file animation.h.

void animation::stop (  )  [inline]

Stops the playback of the animation.

Definition at line 357 of file animation.h.

play_state animation::playstate (  )  const [inline]

Returns whether the animation is currently being played.

Returns:
PLAY is the animation is currently playing, STOP otherwise.

Definition at line 372 of file animation.h.

void animation::rewind (  )  [inline]

Rewinds the animation to it's beginning.

Definition at line 381 of file animation.h.

void animation::next_frame (  ) 

Directly jumps to the next frame.

Definition at line 140 of file animation.cc.

bool animation::update (  )  [virtual]

Updates the animation state.

Reimplemented from drawable.

Definition at line 124 of file animation.cc.

void animation::draw ( s_int16  x,
s_int16  y,
const drawing_area da_opt = NULL,
surface target = NULL 
) const [virtual]

Draw the object on the screen.

Parameters:
x X position where to draw.
y Y position where to draw.
da_opt optional drawing_area to use during the drawing operation.
target pointer to the surface where to draw the drawable. If NULL, draw on the screen.

Implements drawable.

Definition at line 146 of file animation.cc.

s_int8 animation::get ( igzstream file  ) 

Loads an animation from an opened file.

Parameters:
file the opened file from which to load.
Returns:
0 in case of success, error code otherwise.
Todo:
length and height are loaded while they are calculated later. Remove this when format will change.

Definition at line 160 of file animation.cc.

s_int8 animation::load ( string  fname  ) 

Loads an animation from it's filename.

Parameters:
fname the name of the file to load.
Returns:
0 in case of success, error code otherwise.

Definition at line 205 of file animation.cc.

s_int8 animation::put ( ogzstream file  )  const

Saves an animation into an opened file, in game format, with alpha and mask values.

Warning:
as the animation which is saved comes from a screen's depth surface, it will be slightly altered during the save. If you want a class capable of saving animations with full truecolor quality, use animation_edit instead.
Parameters:
file opened file where to save into.
Returns:
  • 0 in case of success.
  • -1 in case of error.
See also:
save ()

Definition at line 217 of file animation.cc.

s_int8 animation::save ( string  fname  )  const

Saves an animation into an file, in game format, with alpha and mask values.

Warning:
as the animation which is saved comes from a screen's depth surface, it will be slightly altered during the save. If you want a class capable of saving animations with full truecolor quality, use animation_edit instead.
Parameters:
fname file name where to save into.
Returns:
  • 0 in case of success.
  • -1 in case of error.
See also:
put ()

Definition at line 249 of file animation.cc.

u_int16 animation::nbr_of_frames (  )  const [inline]

Returns the number of frames in this animation.

Returns:
the number of frames in this animation.

Definition at line 496 of file animation.h.

u_int16 animation::nbr_of_images (  )  const [inline]

Returns the number of images in this animation.

Returns:
the number of images in this animation.

Definition at line 507 of file animation.h.

u_int16 animation::currentframe (  )  const [inline]

Returns the index of the currently displayed frame.

Returns:
the index of the frame currently displayed.

Definition at line 518 of file animation.h.

void animation::set_currentframe ( u_int16  framenbr  )  [inline]

Sets the current frame.

Parameters:
framenbr the index of the frame to display now.

Definition at line 528 of file animation.h.

s_int16 animation::xoffset (  )  const [inline]

Returns the global X offset of the animation.

Returns:
the global X offset of the animation.

Definition at line 540 of file animation.h.

s_int16 animation::yoffset (  )  const [inline]

Returns the global Y offset of the animation.

Returns:
the global Y offset of the animation.

Definition at line 551 of file animation.h.

void animation::set_offset ( s_int16  x,
s_int16  y 
) [inline]

Set the global offsets of this animation.

Parameters:
x new X global offset.
y new Y global offset.

Definition at line 562 of file animation.h.

animationframe* animation::get_frame ( u_int16  nbr  )  [inline]

Returns a pointer to a desired frame.

Parameters:
nbr the index of the frame to get.
Returns:
pointer to the nbr frame.

Definition at line 586 of file animation.h.

image* animation::get_image ( u_int16  nbr  )  [inline]

Returns a pointer to a desired image.

Parameters:
nbr the index of the image to get.
Returns:
pointer to the nbr image.

Definition at line 598 of file animation.h.

s_int8 animation::insert_image ( const image im,
u_int16  pos 
)

Inserts an image at a given position of the image array.

All the frames will be updated so the operation doesn't affect the animation in any way.

The animation will be responsible for freeing the inserted image.

Parameters:
im pointer to the image to add.
pos index where to add the image.
Returns:
0 in case of success, error code otherwise.

Definition at line 261 of file animation.cc.

s_int8 animation::insert_frame ( const animationframe  af,
u_int16  pos 
)

Inserts a frame at a given position of the animationframe array.

All the frames will be updated so the operation doesn't affect the animation in any way.

Parameters:
af the animationframe to add.
pos index where to add the frame.
Returns:
0 in case of success, error code otherwise.

Definition at line 304 of file animation.cc.

s_int8 animation::delete_image ( u_int16  pos  ) 

Removes an image at a given position.

The image itself will also be deleted (). All the frames will be updated so the operation doesn't affect the animation in any way.

Parameters:
pos The index of the image to remove.
Returns:
0 in case of success, error code otherwise.

Definition at line 282 of file animation.cc.

s_int8 animation::delete_frame ( u_int16  pos  ) 

Removes a frame at a given position.

All the frames will be updated so the operation doesn't affect the animation in any way.

Parameters:
pos The index of the animationframe to remove.
Returns:
0 in case of success, error code otherwise.

Definition at line 324 of file animation.cc.

void animation::zoom ( u_int16  sx,
u_int16  sy,
const animation src 
)

Zooms an animation.

Parameters:
sx Desired X size.
sy Desired Y size.
src Source animation to zoom.

Definition at line 347 of file animation.cc.

animation & animation::operator= ( const animation src  ) 

Animation copy (similar to copy ()).

Attention:
Not available from Python. Use copy () from Python instead.
See also:
copy ()

Definition at line 370 of file animation.cc.

void animation::copy ( const animation src  )  [inline]

Synonym of operator = to guarantee its access from Python.

See also:
operator =

Definition at line 687 of file animation.h.


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