GP32 Changing Sprite Colors


May 9, 2005
I'm making a game with the official Gamepark SDK that uses sprites that are black and white. They are 8 bit sprites. I want to be able to change the color of the white pixels (foreground) and also the black pixels (background) of the sprite. I am able to change the white with the TransBlt function but how do I change the black parts? I assume that I can't change the palette colors since it will affect the whole screen.

In the PC version of my game, I was able to do this by getting the color of each pixel in the sprite and seeing if its either black or white. Is there a similar way of doing that using the SDK?
Ok, so a sprite is simply an array of integers. In your case, these are 8bit numbers (u8) since you're working with a 256 color pallete. So:

To check what color a pixel is its just like this:
if (sprite[pixel]=color) Dostuff;

To change the color it is similar:

sprite[pixel] = color;

where pixel is the X of the pixel you want multiplied by the LENGTH of your sprite.

So you could simply do a FOR-loop that checks what color each pixel is and changes it accordingly. You may want to do this to the screen, or a copy of the sprite, so that the original is kept intact. This is also how the transparency blit function works.

Like this:

for (x=0;x<width;x++) if (sprite[(x * length)] = color) sprite[(x * length)] = newcolor;

Please note that there are probably little typos or other errors in my code. I didn't check. It is just to give you a gist of the concept.

Hope it helps. :)

edit: Oh, and then you blit it of course.

edit2: This is only 1 way to do it. You could do it by changing the pallete (your pallete would have to have multiple blacks), or your could transblit it to a framebuffer to change one color and transblit it again to the screen to change the other. Theres probably more ways than that also.
If you work in 8Bit mode.

reserve some color for this sprite in the palette.
after, POKE the color you want to change, it's the faster solution :D