This function is used to update a sprite from a spritesheet.
void dg_spritesheet_to_sprite(dg_spritesheet_t *sheet, sfSprite *sprite, int id);
dg_spritesheet_to_sprite(sheet, sprite, 3);
void dg_spritesheet_to_sprite(
dg_spritesheet_t *sheet,
sfSprite *sprite,
int id
)
{
sfVector2u image_size = sfTexture_getSize(sheet->sheet);
sfIntRect pos = {0, 0, sheet->x, sheet->y};
for (int i = 0; i < id; i++) {
pos.left += sheet->x;
if (pos.left >= image_size.x) {
pos.top += sheet->y;
pos.left = 0;
}
if (pos.top >= image_size.y) {
pos.top = 0;
pos.left = 0;
}
}
sfSprite_setTexture(sprite, sheet->sheet, id);
sfSprite_setTextureRect(sprite, pos);
}