From 4d4547551cbfa60ff86921e61d86ec0a5004112a Mon Sep 17 00:00:00 2001 From: Sara Date: Thu, 11 May 2023 21:09:23 +0200 Subject: [PATCH] make_spritesheet now works with number of tiles on x and y rather than tile width and height --- src/corelib/render.c | 6 +++--- src/corelib/render.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/corelib/render.c b/src/corelib/render.c index a144493..1c6dec5 100644 --- a/src/corelib/render.c +++ b/src/corelib/render.c @@ -422,14 +422,14 @@ void draw_text(const char *str, SDL_FRect area, text_style_t style, depth_t dept _draw(&d); } -spritesheet_t make_spritesheet(const char *file, int tile_width, int tile_height) { +spritesheet_t make_spritesheet(const char *file, int tiles_x, int tiles_y) { spritesheet_t sheet=(spritesheet_t){ .texture=get_texture(file), .w=0,.h=0, - .tile_width=tile_width, - .tile_height=tile_height, }; SDL_QueryTexture(sheet.texture, NULL, NULL, &sheet.w, &sheet.h); + sheet.tile_width = sheet.w / tiles_x; + sheet.tile_height = sheet.h / tiles_y; return sheet; } diff --git a/src/corelib/render.h b/src/corelib/render.h index 5c71492..2d92c5d 100644 --- a/src/corelib/render.h +++ b/src/corelib/render.h @@ -95,7 +95,7 @@ extern void draw_sprite(const sprite_t* sprite); extern void draw_rect(const rectshape_t* rect); extern void draw_sliced(const nineslice_t* sliced); extern void draw_text(const char* str, SDL_FRect area, text_style_t style, depth_t depth); -extern spritesheet_t make_spritesheet(const char* file, int tile_width, int tile_height); +extern spritesheet_t make_spritesheet(const char* file, int tiles_x, int tiles_y); extern nineslice_t make_nineslice(const char* file, int corner_px, float radius); extern sprite_t make_sprite(const char* file, float x, float y); extern sprite_t sprite_from_spritesheet(spritesheet_t* sheet, int index);