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

Re: [pygame] stupid question



enrike wrote:
how can i make the background of a surface transparent?.
I know its probably stupid question but i cannot find who to do it.
The easiest way is if you save your images in a file format that supports transparency. Pygame can then load the image and use the same transparency.

There are two types of transparency in Pygame. "Colorkey" and "Alpha". Colorkey transparency is the easiest, and I recommend you start with that. This is the same transparency you use in graphics for the web. GIF and PNG are probably the most natural formats for this.

Colorkey transparency means a specific color in the image is not drawn when you blit. Have a look at the Pygame example programs. They load images from a BMP which has no colorkey information. The load_image function assumes the border is transparent, so it gets the color of pixel at the topleft corner and sets that as the image colorkey.

This is also covered in more detail in the Chimp Tutorial.
http://pygame.org/docs/tut/chimp/ChimpLineByLine.html