Change only tile palette

SGDK only sub forum

Moderator: Stef

Post Reply
dub
Very interested
Posts: 99
Joined: Thu Mar 19, 2015 1:26 pm

Change only tile palette

Post by dub » Sun Jun 18, 2017 4:40 pm

I wish to change ingame the palette of tiles (planA / PlanB) for showing part of picture. I have one palette with the good color and one black to hide multiple parts of the picture. (never at the same place). So I can only use 2 palettes because I need the others for sprites. And I'll do that with vblank only.

I write some tiles with color with VDP_setTileMapXY( PLANB, TILE_ATTR_FULL(Pal0,0,0,0,1), x, y) and others in black with VDP_setTileMapXY( PLANB, TILE_ATTR_FULL(Pal1,0,0,0,1), x, y), etc ...

I wish to only change the Palette of some tiles, instead of using setTileMapXY with all values(index, flip....). Something like Tile_Palette(x,y,Pal0); to save cpu time.
Is it possible ? or I need to write my asm function maybe ?

cero
Very interested
Posts: 226
Joined: Mon Nov 30, 2015 1:55 pm

Re: Change only tile palette

Post by cero » Sun Jun 18, 2017 5:57 pm

You can't save cpu time like that, it's a word VRAM write no matter what. If you only passed the palette, the function would have to read the word, change those bits, and write it back - being more than 2x slower.

User avatar
Stef
Very interested
Posts: 2775
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Change only tile palette

Post by Stef » Sun Jun 18, 2017 8:30 pm

But VDP_setTileMapXY(..) itself is really slow, it's better to prepare the whole tilemap in RAM (and a region of the map) and update it in one shot with VDP_setTileMapDataEx(..) or VDP_VDP_setTileMapDataRectEx(..)

dub
Very interested
Posts: 99
Joined: Thu Mar 19, 2015 1:26 pm

Re: Change only tile palette

Post by dub » Mon Jun 19, 2017 6:29 am

cero wrote:You can't save cpu time like that, it's a word VRAM write no matter what. If you only passed the palette, the function would have to read the word, change those bits, and write it back - being more than 2x slower.
Ok, it's logical. I think of that because I also need to change priority.
Stef wrote:But VDP_setTileMapXY(..) itself is really slow, it's better to prepare the whole tilemap in RAM (and a region of the map) and update it in one shot with VDP_setTileMapDataEx(..) or VDP_VDP_setTileMapDataRectEx(..)
In my case, I load my tileset with IMAGE and I use an array for drawing tiles.
For using VDP_setTileMapDataEx or VDP_setTileMapDataRectEx, I need to load a premade picture so I'll have a different tileset for each picture and a map->tilemap in ram. So if I use VDP_setTileMapDataRectEx, The sgdk already know the tilemap.
I'll make some tests.

dub
Very interested
Posts: 99
Joined: Thu Mar 19, 2015 1:26 pm

Re: Change only tile palette

Post by dub » Mon Jun 19, 2017 9:52 am

After some tests, I use setMapEx and seems to work well :

Code: Select all

VDP_loadTileSet(myRoom[0]->tileset, ind, NULL);
   
   VDP_setMapEx(PLAN_B, myRoom[0]->map, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind), 0, 1, 0, 0, 24, 22);
   VDP_setMapEx(PLAN_A, myRoom[0]->map, TILE_ATTR_FULL(PAL0, TRUE, FALSE, FALSE, ind), 24, 13, 24, 12, 16, 10);
I need two plans because of the Priority.

I try VDP_setTileMapDataEx(..) and VDP_setTileMapDataRectEx(..) but never find the right value for data :

Code: Select all

void VDP_setTileMapDataEx 	( 	u16  	plan,		const u16 *  	data, ...
data	tile attributes data pointer (see TILE_ATTR_FULL() and TILE_ATTR() macros). 
 

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests