Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Set color key in scene module
-
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:
- 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.
- Find a colorkey function. No clue how to do that.
- Be open to suggestions. I know how to do that.
-
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 theband
argument means though. -
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.