Skip to content

Module: animation

Synopsis

#include <core/animation.h>

Drawable animations.

Animations are small objects using a sprite to update itself and draw next frames depending on delay set.

Structs

animation

Field Access Type
sprite (+&) struct sprite *
row (+) unsigned int
column (+) unsigned int
delay (+) unsigned int
elapsed (-) unsigned int

sprite

The sprite file to use.

row

Current row to be shown.

column

Current column to be shown.

delay

Delay between each frame in milliseconds.

elapsed

Elapsed time since last frame.

Functions

animation_init

Initialize the animation an with the sprite sprite using a delay between each frame.

Note

This function can be omitted if the object is set using designated initializers (setting other fields to 0).

void
animation_init(struct animation *an, struct sprite *sprite, unsigned int delay)

animation_start

Start or reset the animation an to the beginning.

void
animation_start(struct animation *an)

animation_completed

Returns true if the animation an was completely shown.

bool
animation_completed(const struct animation *an)

animation_update

Update the animation an with ticks since last frame. Returns true if it has completed.

bool
animation_update(struct animation *an, unsigned int ticks)

animation_draw

Draw the animation an to the given x, y coordinates.

Warning

You must not call this function is the animation is complete.

bool
animation_draw(const struct animation *an, int x, int y)

animation_drawable

Fill the dw drawable with functions to draw the animation an at the coordinates x, y.

Important

The animation is only borrowed and must be kept valid during the whole dw lifetime.

void
animation_drawable(struct animation *an, struct drawable *dw, int x, int y);

Examples

Initialize using designated initializers

struct animation an = {
    .sprite = &my_sprite,
    .delay = 50
};

Using animation_init

struct animation an;

animation_init(&an, &my_sprite, 50);