Download Tutorial C Files H Files

dg_cpt_sprite

This function is used to create a sprite component.

Usage

dg_component_t *dg_cpt_sprite(sfVector2f *scale);

Example

dg_entity_add_component(player, dg_cpt_sprite(&scale));

Source code

static void component_destroy(void *data)
{
    sfSprite *sprite = (sfSprite *)(data);

    sfSprite_destroy(sprite);
}

dg_component_t *dg_cpt_sprite(sfVector2f *scale)
{
    dg_cpt_destroy_t destroy = &component_destroy;
    sfSprite *sprite = sfSprite_create();
    dg_component_t *component = dg_component_create("sprite", sprite, destroy);

    if (scale)
        sfSprite_setScale(sprite, *scale);
    return component;
}