make_spritesheet now works with number of tiles on x and y rather than tile width and height

pull/5/head
Sara 2023-05-11 21:09:23 +02:00
parent 6fb60c254d
commit 4d4547551c
2 changed files with 4 additions and 4 deletions

View File

@ -422,14 +422,14 @@ void draw_text(const char *str, SDL_FRect area, text_style_t style, depth_t dept
_draw(&d); _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){ spritesheet_t sheet=(spritesheet_t){
.texture=get_texture(file), .texture=get_texture(file),
.w=0,.h=0, .w=0,.h=0,
.tile_width=tile_width,
.tile_height=tile_height,
}; };
SDL_QueryTexture(sheet.texture, NULL, NULL, &sheet.w, &sheet.h); 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; return sheet;
} }

View File

@ -95,7 +95,7 @@ extern void draw_sprite(const sprite_t* sprite);
extern void draw_rect(const rectshape_t* rect); extern void draw_rect(const rectshape_t* rect);
extern void draw_sliced(const nineslice_t* sliced); 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 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 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 make_sprite(const char* file, float x, float y);
extern sprite_t sprite_from_spritesheet(spritesheet_t* sheet, int index); extern sprite_t sprite_from_spritesheet(spritesheet_t* sheet, int index);