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

Re: [pygame] Surfaces with Transparent Backgrounds

Transparency is often a problem because image editors and viewers not always display the same sorts of transparency.

To create a transparent background, load it from an image with transparency. Png supports it, but not all png editors do. I managed to get transparency done by using GIMP (http://www.gimp.org/). In this editor, you need to add a transparency channel to the image, select the part that you want to be transparent and delete it (with the Delete key). This usually does the trick, but people more experient with image editing might have better ways.

Pygame can also do transparency by using color keys, which means defining a specific RGB color that will represent transparent pixel.  In your example, that would be white (0, 0, 0). Use http://www.pygame.org/docs/ref/surface.html#Surface.set_colorkey for this kind of transparency.

On Thu, Aug 20, 2009 at 22:46, pymike <pymike93@xxxxxxxxx> wrote:

I have a function that loads image strips and returns the images in lists. To do this, I create new surfaces and blit the strips to them at an offset.

My question is: Is there a way to create surfaces with transparent backgrounds? The images have quite a bit of semi-transparent pixels in them, so I can't use colorkeys.


- pymike