[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] question about transparent surfaces and alpha-value



> Hi List,
> just want to make sure i got this right, please correct me if i'm wrong:
> 
> if i have a jpg-file, i can set the transparency with the command 
> 
> pygame.Surface.set_alpha(alpha-value).
> 
> but if i hav a .png-file with already transparent background, i can not
> set the alpha-value of that picture ? Of the visible pixels of
> that .png-file, of course.
> 
> Here is a demo , what i want is the second face (right) also to become
> more and more transparent:
> 
> http://www.spielend-programmieren.at/wiki/doku.php?id=code:colordemo1.py


If I understand correctly, one thing you could try is to fill the
background with a solid color such as bright purple, then use
set_colorkey(), like this:

image = pygame.image.load(filename)
image.set_colorkey((255,0,255))

I think you can then set an alpha value for the image while still having
the pixels marked as transparent not show up at all. Use an extreme and
unlikely color like (255,0,255) to reduce the chance that you'll
accidentally make the wrong parts of your image transparent.