Download Tutorial C Files H Files

dg_cpt_animator

This function is used to create an animator component.

Usage

dg_component_t *dg_cpt_animator(dg_animator_t *(*set_animator)(void));

Example

dg_entity_add_component(player, dg_cpt_animator(&set_player_animator));

Source code

static void component_destroy(void *data)
{
    dg_animator_t *animator = (dg_animator_t *)(data);
    dg_animation_t *anim = 0;

    for (int i = 0; i < animator->length; i++) {
        anim = animator->animations[i];
    }
    dg_animator_free(animator);
}

dg_component_t *dg_cpt_animator(dg_animator_t *(*set_animator)(void))
{
    dg_cpt_destroy_t destroy = &component_destroy;
    dg_animator_t *animator = set_animator();
    dg_component_t *component = dg_component_create("animator",
        animator, destroy);

    return component;
}