Download Tutorial C Files H Files

dg_cpt_pos

This function is used to create a position component.

Usage

dg_component_t *dg_cpt_pos(int x, int y);

Example

dg_entity_add_component(entity, dg_cpt_pos(x, y));

Source code

static void component_destroy(void *data)
{
    sfVector2f *pos = (sfVector2f *)(data);

    free(pos);
}

dg_component_t *dg_cpt_pos(int x, int y)
{
    void (*destroy)(void *) = &component_destroy;
    sfVector2f *pos = 0;
    dg_component_t *component = 0;

    pos = malloc(sizeof(sfVector2f));
    pos->x = x;
    pos->y = y;
    component = dg_component_create("pos", pos, destroy);
    return component;
}