gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Ham text is messing up my tiles

#63722 - Liquid_Dark - Thu Dec 15, 2005 8:57 pm

When I use Ham's DrawText functions, I'm getting a messed up tile set.
My code is pretty simple:

IN GAME INITIALIZATION:
// load bg tiles
ham_SetBgMode(0);
ham_LoadBGPal((void *)bg_Palette, 16);
ham_bg[0].ti = ham_InitTileSet((void *)bg_Tiles, SIZEOF_16BIT(bg_Tiles), 1, 1);
ham_InitText(0);

//load map
ham_bg[0].mi = ham_InitMapEmptySet(3, 0);
map_fragment_info_ptr bgLevel = ham_InitMapFragment((void *)bg_Map, 30, 20, 0, 0, 30, 20, 0);
ham_InsertMapFragment(bgLevel, 0, 0, 0);

// display level
ham_InitBg(0, 1, 0, 0);
ham_SetBgXY(0, 0, 0);

IN GAME LOOP:
ham_DrawText(1,1,"Score: %d",score);
ham_DrawText(1,16,"High Score: %d",highscore);


What I get is not what I want:
[Images not permitted - Click here to view it]

Any idea how to fix this?

#64761 - Peter - Mon Dec 26, 2005 1:26 pm

Liquid_Dark wrote:
Any idea how to fix this?


Use a background-layer for ham_InitText which is not used by anything else. In your code you use bg 0, it is used for the text and an extra-map. Put ham_InitText before the palette loading function. I'm not 100% certain, but I think ham_InitText overwrites two entries of the palette in Vram.

Not sure if it is a bug or a feature, you only store 16 colors to Vram for your tileset, but you initialize an 8bit tileset (ham_InitTileSet).

Hope it helps