fix mem leak and improve spritesheet explorer
parent
bdd43143f8
commit
5aa90fc5af
|
@ -93,28 +93,33 @@ void platform_input() {
|
||||||
|
|
||||||
void debug_draw_spritesheet() {
|
void debug_draw_spritesheet() {
|
||||||
if (nk_begin(game_ui, "Spritesheet debug", nk_rect(660, 100, 240, 800),
|
if (nk_begin(game_ui, "Spritesheet debug", nk_rect(660, 100, 240, 800),
|
||||||
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| NK_WINDOW_TITLE))
|
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|NK_WINDOW_TITLE))
|
||||||
{
|
{
|
||||||
nk_layout_row_dynamic(game_ui, 0, 1);
|
nk_layout_row_dynamic(game_ui, 0, 2);
|
||||||
|
|
||||||
static int spritesheet_frame_id = 0;
|
static int spritesheet_frame_id = 0;
|
||||||
if(nk_button_label(game_ui, "Prev")){
|
if(nk_button_label(game_ui, "Prev")){
|
||||||
spritesheet_frame_id-=10;
|
spritesheet_frame_id-=100;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(nk_button_label(game_ui, "Next")){
|
if(nk_button_label(game_ui, "Next")){
|
||||||
spritesheet_frame_id+=10;
|
spritesheet_frame_id+=100;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool loaded = false;
|
static bool loaded = false;
|
||||||
static struct nk_image nuclear_image;
|
static struct nk_image nuclear_image;
|
||||||
|
static int max_frames = 0;
|
||||||
if (!loaded) {
|
if (!loaded) {
|
||||||
nuclear_image = TextureToNuklear(main_sprite_sheet.texture);
|
nuclear_image = TextureToNuklear(main_sprite_sheet.texture);
|
||||||
|
max_frames = nuclear_image.w*nuclear_image.h / (32*32);
|
||||||
|
zpl_printf("pica %d\n", max_frames);
|
||||||
|
loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
nk_layout_row_static(game_ui, 32, 32, 6);
|
nk_layout_row_static(game_ui, 32, 32, (int)(nk_window_get_size(game_ui).x / 32.f) -1);
|
||||||
for(size_t i = 0; i < 10; i++) {
|
for(int i = 0; i < 100; i++) {
|
||||||
int frame = spritesheet_frame_id + i;
|
int frame = spritesheet_frame_id + i;
|
||||||
|
frame %= max_frames;
|
||||||
float ox = (frame % main_sprite_sheet.framesWide) * main_sprite_sheet.frameSize.x;
|
float ox = (frame % main_sprite_sheet.framesWide) * main_sprite_sheet.frameSize.x;
|
||||||
float oy = (int)(frame / main_sprite_sheet.framesWide) * main_sprite_sheet.frameSize.y;
|
float oy = (int)(frame / main_sprite_sheet.framesWide) * main_sprite_sheet.frameSize.y;
|
||||||
nuclear_image.region[0] = (nk_short)ox;
|
nuclear_image.region[0] = (nk_short)ox;
|
||||||
|
|
Loading…
Reference in New Issue