animation

struct animation

struct animation

Animation frames and durations for a sprite. You may use the same animation definition for any number of sprites:

struct animation* walk = create_animation();

add_frame(walk, 0, 50, NULL);
add_frame(walk, 1, 100, NULL);
add_frame(walk, 2, 50,NULL);

...
play_animation(zombie, walk);
...
play_animation(robot, walk);

You may also associate custom data with specific key frames.

struct frame

struct frame

Animation frame

animation modes

enum animation_mode

Animation playback mode

Values:

LOOP_FRAMES

Loop back to loop_from

PINGPONG_FRAMES

go back in reverse and then return endlessly

FREEZE_LAST_FRAME

stop at the last frame

create_animation

struct animation *create_animation(void)

Create a new animation.

Return
New animation instance, ready to have frames added using add_frame().

destroy_animation

void destroy_animation(struct animation *animation)

Destory a previously created animation.

Parameters
  • animation -

    A previously created /ref animation to deallocate.

add_frame

void add_frame(struct animation *animation, int index_in_sprite, int duration, void *userdata)

Add a new frame to an animation

Parameters
  • animation -

    Animation to add the frame to

  • index_in_sprite -

    The frame index in the sprite frames image

  • duration -

    The time in milliseconds to play this frame

  • userdata -

    Any data you would like to associate with this frame You will get this data pointer back when this frame gets played

add_frames

void add_frames(struct animation *animation, int nframes, struct frame frames[])

Add a new set of frames to an animation.

Parameters
  • animation -

    Animation to add the frame to

  • nframes -

    Number of frames to add

  • frames -

    The frames to add as an array of frame structs