How to update a switced palette on background

SGDK only sub forum

Moderator: Stef

Post Reply
Boyfinn
Very interested
Posts: 57
Joined: Sat Aug 08, 2015 12:12 pm
Location: Lapland, Finland

How to update a switced palette on background

Post by Boyfinn » Sat Dec 02, 2017 9:34 pm

I'm trying to switch palettes quickly on PLAN_B.
But for some reason only the last palette of the sequence of 4 is set.
It skips over 3 palettes.

How do i update the backround palette quickly enough so that the palette change could be seen?

Miquel
Very interested
Posts: 514
Joined: Sat Jul 30, 2016 12:33 am

Re: How to update a switced palette on background

Post by Miquel » Sat Dec 02, 2017 11:45 pm

There is no reason to skip palettes other than a programming mistake. The first thing comes to mind is to check vpd increment counter value.

There are two ways:
a) Change the palettes values themselves
b) Change tiles palette number

If for some reason you are going for B, you can do it in a single frame but only just. A tile table is 4KB in size*, but you only need to change every other byte, so with a clever programming you only need to change 2KB. Is doable but not easy: think carefully.
An advice: do it in vblank, avoid display period because it becomes really slow, and 2KB is quite a big chunk. As the game grows and you use more and more cpu you will notice an slow down.

* It could be bigger but it's completely unnecessary
HELP. Spanish TVs are brain washing people to be hostile to me.

Miquel
Very interested
Posts: 514
Joined: Sat Jul 30, 2016 12:33 am

Re: How to update a switced palette on background

Post by Miquel » Sun Dec 03, 2017 12:01 am

I just remember another option:
Stop the action, do the changes you need taking as much frames as you need, finally restart game as normal.

This technique was used a lot by Nintendo games on SNES which has a much slower bandwidth with the video chip. The only thing is you need to do it "beautiful", like a detailed animation sequence to be successful.
HELP. Spanish TVs are brain washing people to be hostile to me.

Boyfinn
Very interested
Posts: 57
Joined: Sat Aug 08, 2015 12:12 pm
Location: Lapland, Finland

Re: How to update a switced palette on background

Post by Boyfinn » Sun Dec 03, 2017 1:19 pm

Right now i'm using VDP_setPaletteColors.
The problem i'm having is that when i call my function which contains a sequence of palette changes within a loop, Only the last change will be applied.
IE:

Code: Select all

void ScrollPalettes
{
for(blabla = 0; blabla < NumOfDefinedPalettes; blabla ++)
  {
    VDP_setPaletteColors(0,arrayOfPalettes[blabla],16);
  }
}
I also tried doing it without a loop

Code: Select all

void ScrollPalettes
{
VDP_setPaletteColors(0, predefinedpalette0, 16);
VDP_setPaletteColors(0, predefinedpalette1, 16);
VDP_setPaletteColors(0, predefinedpalette2, 16);
VDP_setPaletteColors(0, predefinedpalette3, 16);
}
But only the last palette change gets executed and shows on screen, All the other palette changes happen in between frames and don't get a chance to be applied and displayed.

EDIT:
I got it working with VDP_waitVsync.
However, i still have a problem.
I'm trying to change the PLAN_B image in the background while the palette change happends.
Knowing that there's a small delay when changing background images i tried to load the new image while the palette change is happening(Which takes a couple frames).
However, Calling the VDP draw image after calling the palette change function, causes the loading to start after the whole palette scroll sequence is over.
Is there any way to initiate the VDP_drawImage loading while the palette scrolling function is working and then immediately changing the BG layer to that image once the palette change is done?

Post Reply