-
Notifications
You must be signed in to change notification settings - Fork 8k
Open
Labels
Description
stb_tilemap_editor.h show in the editor incorrect tile that appear in the palette preview
See the issue in the image below:

To fix this issue;
Replace this line in stbte__tile_in_palette:
STBTE_DRAW_TILE(x, y, id, slot == tm->cur_tile, 0);
with this:
STBTE_DRAW_TILE(x, y, slot, slot == tm->cur_tile, 0);
See more details in the example below:
static void stbte__tile_in_palette(stbte_tilemap *tm, int x, int y, int slot)
{
stbte__tileinfo *t = &tm->tiles[slot];
int x0=x, y0=y, x1 = x+tm->palette_spacing_x - 1, y1 = y+tm->palette_spacing_y;
int id = STBTE__ID(STBTE__palette, slot);
stbte__hittest(x0,y0,x1,y1, id);
switch (stbte__ui.event) {
case STBTE__paint:
stbte__draw_rect(x,y,x+tm->palette_spacing_x-1,y+tm->palette_spacing_x-1, STBTE_COLOR_TILEPALETTE_BACKGROUND);
// PATCH by Aero 3D Dev:
// The original code used an internal UI ID for drawing palette tiles,
// which caused incorrect graphics to appear in the palette preview.
// Replaced the ID with `slot` so STBTE_DRAW_TILE renders the actual
// atlas tile. This makes the palette preview match the brush and grid.
STBTE_DRAW_TILE(x,y,slot, slot == tm->cur_tile,0);
if (slot == tm->cur_tile)
stbte__draw_frame_delayed(x-1,y-1,x+tm->palette_spacing_x,y+tm->palette_spacing_y, STBTE_COLOR_TILEPALETTE_OUTLINE);
break;
default:
if (stbte__button_core(id))
tm->cur_tile = slot;
break;
}
}
See the correct tile appear in the palette preview below after the changes have been made:

hope this helps someone and would like to hear if this was a good suggestion to fix this problem.
Reactions are currently unavailable