Move some of the sprite math out of the actor into the sprite
This commit is contained in:
21
src/sprite.c
21
src/sprite.c
@@ -13,6 +13,27 @@
|
||||
#include <akgl/staticstring.h>
|
||||
#include <akgl/iterator.h>
|
||||
|
||||
akerr_ErrorContext *akgl_sprite_sheet_coords_for_frame(akgl_Sprite *self, SDL_FRect *srccoords, uint8_t frameid)
|
||||
{
|
||||
PREPARE_ERROR(e);
|
||||
|
||||
FAIL_ZERO_RETURN(e, self, AKERR_NULLPOINTER, "NULL sprite");
|
||||
FAIL_ZERO_RETURN(e, srccoords, AKERR_NULLPOINTER, "NULL SDL_Rect");
|
||||
FAIL_ZERO_RETURN(e, self->sheet, AKERR_NULLPOINTER, "NULL spritesheet");
|
||||
|
||||
srccoords->x = self->width * self->frameids[frameid];
|
||||
if ( srccoords->x >= self->sheet->texture->w ) {
|
||||
srccoords->y = ((int)srccoords->x / self->sheet->texture->w) * self->height;
|
||||
srccoords->x = ((int)srccoords->x % self->sheet->texture->w);
|
||||
} else {
|
||||
srccoords->y = 0;
|
||||
}
|
||||
srccoords->w = self->width;
|
||||
srccoords->h = self->height;
|
||||
|
||||
SUCCEED_RETURN(e);
|
||||
}
|
||||
|
||||
static akerr_ErrorContext *akgl_sprite_load_json_spritesheet(json_t *json, akgl_SpriteSheet **sheet, char *relative_path)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
|
||||
Reference in New Issue
Block a user