Download Tutorial C Files H Files

dg_animator_add

This function is used to add an animation to the animator.

Usage

void dg_animator_add(dg_dg_animation_t * animator, char * key, dg_animation_t *animation);

Example

dg_animator_add(player, "walk", walk);

Source code

void dg_animator_add(dg_animation_t * animator, char * key, dg_animation_t *animation)
{
    dg_animation_t **new_anim_list = 0;
    char **new_key_list = 0;

    new_anim_list = malloc(sizeof(dg_animation_t *) * (animator->length + 1));
    new_key_list = malloc(sizeof(char *) * (animator->length + 1));
    if (animator->length != 0) {
        for (int i = 0; i < animator->length; i++) {
            new_anim_list[i] = animator->animations[i];
            new_key_list[i] = animator->keys[i];
        }
        free(animator->animations);
        free(animator->keys);
    }
    new_anim_list[animator->length] = animation;
    new_key_list[animator->length] = key;
    animator->animations = new_anim_list;
    animator->keys = new_key_list;
    animator->length++;
}