Download Tutorial C Files H Files

dg_animation_add

This function is used to add a frame in the animation.

Usage

void dg_animation_add(dg_animation_t *animation, int i)

Example

animation_add(animation, 2);

Source code

void dg_animation_add(dg_animation_t *animation, int i)
{
    int *new_list = 0;
    if (!(animation->frames)) {
        animation->frames = malloc(sizeof(int));
        animation->frames[0] = i;
        animation->size = 1;
    } else {
        new_list = malloc(sizeof(int) * (animation->size + 1));
        for (int i = 0; i < animation->size; i++)
            new_list[i] = animation->frames[i];
        new_list[animation->size] = i;
        animation->size++;
        free(animation->frames);
        animation->frames = new_list;
    }
}