3
votes

I'm currently making a game, in which I load the sprites and backgrounds from images (PNG) using the pygame.image.load() function.

My problem is that not all of my sprites are rectangular - and because of that they leave ugly white-space on the background that I blitted them on to. On the image below, the white is part of the ship sprite, however I would want it to blend in with the background.

enter image description here

Is there an easy way to solve this? Thanks in advance for any help.

1
Are you sure the ship image itself is transparent? I've managed to load transparent .pngs just fine. Also, what software did you use to make that image? - ASCIIThenANSI

1 Answers

3
votes

If image has transparent background (some pixels are transparent) (PNG) then you have to use convert_alpha()

 image = pygame.image.load(filename).convert_alpha()

If image has no transparent background (GIF, JPG) then you can use set_colorkey() and pygame will treat selected color as transparent.

 image = pygame.image.load(filename).set_colorkey(color)

Many sprites images use pink as key color

enter image description here