Adonthell  0.4
animation Class Reference

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

#include <animation.h>

Inheritance diagram for animation:
Collaboration diagram for animation:

Public Member Functions

 animation ()
 Default constructor. More...
 
 ~animation ()
 Destructor. More...
 
void clear ()
 Clears an animation, that is put it back into the original (constructor) state. More...
 
animationoperator= (const animation &src)
 Animation copy (similar to copy ()). More...
 
void copy (const animation &src)
 Synonym of operator = to guarantee its access from Python. More...
 
Playback control methods.
void play ()
 Starts the playback of the animation. More...
 
void stop ()
 Stops the playback of the animation. More...
 
play_state playstate () const
 Returns whether the animation is currently being played. More...
 
void rewind ()
 Rewinds the animation to it's beginning. More...
 
void next_frame ()
 Directly jumps to the next frame. More...
 
State updating Methods.
bool update ()
 Updates the animation state. More...
 
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. More...
 
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. More...
 
s_int8 load (string fname)
 Loads an animation from it's filename. More...
 
s_int8 put (ogzstream &file) const
 Saves an animation into an opened file, in game format, with alpha and mask values. More...
 
s_int8 save (string fname) const
 Saves an animation into an file, in game format, with alpha and mask values. More...
 
Global animation properties Methods.
u_int16 nbr_of_frames () const
 Returns the number of frames in this animation. More...
 
u_int16 nbr_of_images () const
 Returns the number of images in this animation. More...
 
u_int16 currentframe () const
 Returns the index of the currently displayed frame. More...
 
void set_currentframe (u_int16 framenbr)
 Sets the current frame. More...
 
s_int16 xoffset () const
 Returns the global X offset of the animation. More...
 
s_int16 yoffset () const
 Returns the global Y offset of the animation. More...
 
void set_offset (s_int16 x, s_int16 y)
 Set the global offsets of this animation. More...
 
Image and Animationframe control Methods.
animationframeget_frame (u_int16 nbr)
 Returns a pointer to a desired frame. More...
 
imageget_image (u_int16 nbr)
 Returns a pointer to a desired image. More...
 
s_int8 insert_image (const image *im, u_int16 pos)
 Inserts an image at a given position of the image array. More...
 
s_int8 insert_frame (const animationframe af, u_int16 pos)
 Inserts a frame at a given position of the animationframe array. More...
 
s_int8 delete_image (u_int16 pos)
 Removes an image at a given position. More...
 
s_int8 delete_frame (u_int16 pos)
 Removes a frame at a given position. More...
 
Special FX methods.
void zoom (u_int16 sx, u_int16 sy, const animation *src)
 Zooms an animation. More...
 
- Public Member Functions inherited from drawable
 drawable ()
 Default constructor. More...
 
virtual ~drawable ()
 Destructor. More...
 
u_int16 length () const
 Returns the length of the drawable. More...
 
u_int16 height () const
 Returns the height of the drawable. More...
 
virtual bool input_update ()
 Virtual input update function, provided for objects which doesn't need one. More...
 

Friends

class win_anim
 

Additional Inherited Members

- Protected Member Functions inherited from drawable
void set_length (u_int16 l)
 Sets the length of the drawable. More...
 
void set_height (u_int16 h)
 Sets the height of the drawable. More...
 

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:

  • A set of images arranged in an indexed array.
  • A set of animation_frames.
  • A global position offset.

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 312 of file animation.h.

Constructor & Destructor Documentation

§ animation()

animation::animation ( )

Default constructor.

Definition at line 100 of file animation.cc.

§ ~animation()

animation::~animation ( )

Destructor.

Definition at line 121 of file animation.cc.

Member Function Documentation

§ clear()

void animation::clear ( )

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

Definition at line 105 of file animation.cc.

§ play()

void animation::play ( )
inline

Starts the playback of the animation.

Definition at line 348 of file animation.h.

§ stop()

void animation::stop ( )
inline

Stops the playback of the animation.

Definition at line 361 of file animation.h.

§ playstate()

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 376 of file animation.h.

§ rewind()

void animation::rewind ( )
inline

Rewinds the animation to it's beginning.

Definition at line 385 of file animation.h.

§ next_frame()

void animation::next_frame ( )

Directly jumps to the next frame.

Definition at line 143 of file animation.cc.

§ update()

bool animation::update ( )
virtual

Updates the animation state.

Reimplemented from drawable.

Definition at line 127 of file animation.cc.

§ draw()

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
xX position where to draw.
yY position where to draw.
da_optoptional drawing_area to use during the drawing operation.
targetpointer to the surface where to draw the drawable. If NULL, draw on the screen.

Implements drawable.

Definition at line 149 of file animation.cc.

§ get()

s_int8 animation::get ( igzstream file)

Loads an animation from an opened file.

Parameters
filethe 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 163 of file animation.cc.

§ load()

s_int8 animation::load ( string  fname)

Loads an animation from it's filename.

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

Definition at line 208 of file animation.cc.

§ put()

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
fileopened file where to save into.
Returns
  • 0 in case of success.
  • -1 in case of error.
See also
save ()

Definition at line 220 of file animation.cc.

§ save()

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
fnamefile name where to save into.
Returns
  • 0 in case of success.
  • -1 in case of error.
See also
put ()

Definition at line 252 of file animation.cc.

§ nbr_of_frames()

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 500 of file animation.h.

§ nbr_of_images()

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 511 of file animation.h.

§ currentframe()

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 522 of file animation.h.

§ set_currentframe()

void animation::set_currentframe ( u_int16  framenbr)
inline

Sets the current frame.

Parameters
framenbrthe index of the frame to display now.

Definition at line 532 of file animation.h.

§ xoffset()

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 544 of file animation.h.

§ yoffset()

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 555 of file animation.h.

§ set_offset()

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

Set the global offsets of this animation.

Parameters
xnew X global offset.
ynew Y global offset.

Definition at line 566 of file animation.h.

§ get_frame()

animationframe* animation::get_frame ( u_int16  nbr)
inline

Returns a pointer to a desired frame.

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

Definition at line 590 of file animation.h.

§ get_image()

image* animation::get_image ( u_int16  nbr)
inline

Returns a pointer to a desired image.

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

Definition at line 602 of file animation.h.

§ insert_image()

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
impointer to the image to add.
posindex where to add the image.
Returns
0 in case of success, error code otherwise.

Definition at line 264 of file animation.cc.

§ insert_frame()

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
afthe animationframe to add.
posindex where to add the frame.
Returns
0 in case of success, error code otherwise.

Definition at line 307 of file animation.cc.

§ delete_image()

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
posThe index of the image to remove.
Returns
0 in case of success, error code otherwise.

Definition at line 285 of file animation.cc.

§ delete_frame()

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
posThe index of the animationframe to remove.
Returns
0 in case of success, error code otherwise.

Definition at line 327 of file animation.cc.

§ zoom()

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

Zooms an animation.

Parameters
sxDesired X size.
syDesired Y size.
srcSource animation to zoom.

Definition at line 350 of file animation.cc.

§ operator=()

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 373 of file animation.cc.

§ copy()

void animation::copy ( const animation src)
inline

Synonym of operator = to guarantee its access from Python.

See also
operator =

Definition at line 691 of file animation.h.


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