Search code examples
pythonimagepygamepngtransparency

Python Pygame, image has white background even if it's PNG and I did not designate white background


I am building a silly game in Python using Pygame. I have a cat that poops. And in a previous version these poops had a transparent background. So I want to make my poops in a class for clarity of mind and control. And now my poops have a white background... I am at a loss to why this is happening.

  • The images are PNG
  • The images are of type surface and use 32 depth which allows for transparency.

Here is a link to my https://github.com/ironsketch/catPoop/blob/cat3.0/catNewGame.py


Solution

  • Images with transparency have to be converted with convert_alpha instead of the convert method.

    You could also use convert and then set_colorkey, but as far as my experience goes, surfaces that are converted with convert_alpha are blitted a lot faster.