views:

412

answers:

2

I'm trying to blit a PNG image onto a surface, but the transparent part of the image turns black for some reason, here's the simple code:

screen = pygame.display.set_mode((800, 600), pygame.DOUBLEBUF, 32)

world = pygame.Surface((800, 600), pygame.SRCALPHA, 32)
treeImage = pygame.image.load("tree.png")

world.blit(treeImage, (0,0), (0,0,64,64))
screen.blit(world, pygame.rect.Rect(0,0, 800, 600))

What do I have to do to solve the problem? The image has alpha transparency, I've opened it up in PhotoShop and the background turns transparent, not black or white or any other color.

Thank you for your support :)

+3  A: 

http://www.pygame.org/docs/ref/image.html recommends:

For alpha transparency, like in .png images use the convert_alpha() method after loading so that the image has per pixel transparency.

Nick T
pygame.image.load will already have alpha when loaded from an image with alpha.
Peter Shinners
A: 

Your code looks like it should be correct. The SDL library does not support alpha to alpha blitting like this, but Pygame added support for it awhile ago. In Pygame 1.8 support was added for custom blending modes, and I wonder if that removed Pygame's internal alpha-to-alpha blitter?

Alas, further investigation will be required.

Peter Shinners