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 > Sprites on screen

#34752 - Mitch GBA - Tue Jan 25, 2005 4:29 pm

Hi. I'm brand new to GBA AND C/C++, and I'm trying to make a game :) So far I've got a very basic platform movement working, but I dont like the sprites, because of the black. How can you set a certain color as transparant? Like, you have your sprite, and what shouldn't be drawn to the screen, is black. How do you get rid of the black? :)

Thanks in advance,
Mitch

#34754 - zazery - Tue Jan 25, 2005 5:09 pm

I believe the first color in your palette regardless of colour is transparent. That is why you may have seen sprites with pink or green coloured backgrounds; they use either uncommon color as their transparency as opposed to black. In order for you to set a different color transparent, try rearranging your palette in a graphics program. For more information consult GBAtek.

#34756 - ScottLininger - Tue Jan 25, 2005 6:02 pm

Mitch,

What graphics tool are you using? Photoshop? Paint?

If you're using a GFX2SpriteHeader kind of conversion tool, you can always mess with the actual header data. It's a hack, but it works. Like Zazery said, every pixel that is set to index color "00" will be transparent.

Typical Header dump tools will give you something like this...

Code:
const u16 MyImageData[] = { 0x7575, 0x7556, 0x1756 ...


By looking at the data, you should be able to determine which index is currently pointing to black, then do a search and CHANGE it to point to index #0.

With U16 arrays, two pixels get stored in every array entry. So the 1st entry above, 0x7575, means that the first and second pixel are both index color #75. If you wanted those to be transparent, then you'd do two search and replaces...

First, replace "x75" with "x00"

Second, replace "75," with "00,"

If you don't do it with two searches, you would miss the transparent pixel that is pixel #3 in the example above (0x7556), and if you don't do it with the leading "x" and trailing "," you would accidentally replace the two middle numbers of the third entry, 0x1756.

In the end, your new array should look like...

Code:
const u16 MyImageData[] = { 0x0000, 0x0056, 0x1756 ...


...which will display the 1st three pixels as transparent.

But really the best way is to alter the original images so the transparent bits point to color#0. But how to do this depends on your tools.

Cheers,

Scott

#34772 - Mitch GBA - Wed Jan 26, 2005 12:12 am

Thanks :D