Reputation: 2821
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.
Is there an easy way to solve this? Thanks in advance for any help.
Upvotes: 3
Views: 848
Reputation: 142641
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
Upvotes: 3