Forum Archive

Set color key in scene module

jb145491

Anybody here who has used the pygame module before should know about a colorkey. How do I set it?

PS. In case anybody didn't know, a colorkey is a RGB(A) value that when bound to a picture, replaces all pixels that are the color of the colorkey with another color, or transparent.

Any ideas?

Some thoughts running through my mind:
1. Maybe go pixel by pixel in a for loop. Use an if statement to determine if the pixel is that color. No clue how to do that.
2. Find a colorkey function. No clue how to do that.
3. Be open to suggestions. I know how to do that.

dgelessus

Why use color-keying when PNG files have a real alpha channel? It's a lot less work to convert your textures to PNG and add a proper alpha channel, if you ask me. In any case, PIL.Image.Image.putalpha may be what you're looking for. The docs aren't very clear about what exactly the band argument means though.

jb145491

I have images in my clipboard I am using, plus the colorkey should be pretty easy. In pygame:

pygame.image.set_colorkey(0, 0, 0)
This takes any black on the image and converts it to clear.