PNG Image Sprites retains background color

I am using this sprite for some experiments. I cropped a section of the sheet with GIMP and made the blue background transparent, the result being this. However, when I run the codes using this sprite, I still end up with a sprite with a blue background. Same thing happens with other sprites (different sprite sheet, same source, same editing process).

Now, I know that I can set transparent colors using PyGame itself but I'm wondering if that's the only way I can do it? Can't I do it through the image itself? How come PyGame still reads a blue backgorund even after I have cleared it with GIMP?

P.S. SSCE would be pvz_shooter_test.py and/or image_test.py of the GitHub repo linked.

Answers


Try mySurface.convert_alpha() (check the pygame documentation about it).


Just some more additional details on how come PyGame still read a blue background even after I've cleared it with GIMP.

When the image file format supports it, pixels aren't just represented as RGB bits. There's additional information for every pixel, the alpha channel. What GIMP did is to set the alpha bits to 0% opacity. The RGB values remained (in this instance, blue). Since my PyGame code isn't set to read the additional alpha bits, it only read the RGB describing blue. The convert_alpha method told PyGame to read the alpha channel as well.


Need Your Help

Summing a list of lists of lists?

python list for-loop indexing sum

I'm trying to sum a list of lists of lists in Python but I'm getting the wrong output. I want the number 36 as my answer but I'm getting the sum of each bracket.

Basic Objective-C syntax: "%@"?

c objective-c syntax

I'm working through the Stanford iPhone podcasts and have some basic questions.