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.

Graphics > How do sprite palletes work?

#56049 - thegamefreak0134 - Wed Oct 05, 2005 7:17 pm

OK, I am finally working on a game that makes heavy use of a lot (think of my expirience level, we're talking maybe 20) of sprites. I have questions concerning sprite palletes. When you load a sprite pallete, does it only affect that sprite? Or if you load a new pallete, will it affect all of the sprites?

Also, is there a tool that will, upon conversion, let you choose a transparent color? I usually use Photoshop to convert from .bmp to .pcx, but I noticed after much code digging that it appears to reverse the pallete when it does this.

Finally, about transparent colors. If I define one color at the transparent color in a pallete and then define that same color somewhere else in the pallete, will both of them come up transparent? I need to know this to try and combat photoshop. My intention it to try to make the last color in the pallete my transparent color. Since it will be repeated somewhere in the actual pallete created when I drew the image, I need to know if the GBA diferentiates between the two.

Thanks in advance. If you're unsure of what I'm asking, I can elaborate. Why can't it all just be easy?
_________________
What if the hokey-pokey really is what it's all about?

[url=http:/www.darknovagames.com/index.php?action=recruit&clanid=1]Support Zeta on DarkNova![/url]

#56053 - DiscoStew - Wed Oct 05, 2005 8:19 pm

I'm gonna go out of order with the series of questions you have.

The way the GBA deals with transparency is very simple. If a pixel refers to the very first color of a palette (index 0), then that pixel is not drawn, resulting in the transparency, no matter what color is in index 0. If another color is the same as the color in index 0 but not at index 0, then that color will show up. Anything refereing to index 0 will be cut out, and you can't choose which index the transparency will be. My suggestion is to download PaletteTool from the tools section, which can allow you to rearrange the palette, so that if the color that you want to be the transparency isn't the very first index of the pallete, you can do a simple swap, and the program will do it for you.

As for sprites, the GBA can have up to 256 colors at one time (255 actually for 8-bit color [256 colors], because index 0 is transparent, and 240 for 4-bit color [16 colors], because every 16th index starting from index 0 is transparent). For 8-bit mode, all sprites reference to the same exact palette of 256 colors, whereas in 4-bit mode, sprites can be one of any of the 16 palettes consisting of 16 color each. Attribute0 holds the color type, and Attribute2 holds the palette reference (if using 4-bit mode). It is possible to have some sprites set for 8-bit with others at 4-bit, but you'd need to be very organized with your palette arrangement.

Hope that helps
_________________
DS - It's all about DiscoStew

#56073 - tepples - Wed Oct 05, 2005 9:48 pm

thegamefreak0134 wrote:
OK, I am finally working on a game that makes heavy use of a lot (think of my expirience level, we're talking maybe 20) of sprites. I have questions concerning sprite palletes. When you load a sprite pallete, does it only affect that sprite? Or if you load a new pallete, will it affect all of the sprites?

A 16-color palette will affect only those sprites that have been set to that palette. (There are sixteen such palettes for sprites.) However, a 256-color palette will affect all sprites on screen. Most commercial games do use 16-color palettes and have done so since the Sega Genesis and Super NES.

Unlike Photoshop, GIMP does not reverse the palette, but it does try to make the darkest color into color 0.

Quote:
Finally, about transparent colors. If I define one color at the transparent color in a pallete and then define that same color somewhere else in the pallete, will both of them come up transparent?

No, but a lot of converters will try to collapse them to one color if you convert to RGB and back to indexed, so try to use a unique color (hot pink #ff00ff and sky blue #99ccff are popular) for transparent areas of your sprite.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.