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

Re: [pygame] Get a transparent Surface



This makes a totally transparent surface by setting the surface's transparency to 0--I'm not sure what you would want that for because nothing you draw on it could be seen, so I imagine it is useless:

surface = pygame.Surface((100,100))
surface.set_alpha(0)

If you will be drawing on the surface, you can use colorkeys:

surface = pygame.Surface((100,100))
surface.set_colorkey((0,0,0)) #the default surface color

The disadvantage here is that anything black will be transparent.  You can fill the surface with a convenient color beforehand then set the colorkey to that if you need black.  There are 255**3 possible colors, you probably don't need all of them.

There is probably a way to set certain pixels transparent before-hand, and you might look into masks.  You can also just load an image with alpha values and use .convert_alpha() on the surface

Hope this helps,
Ian