[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] how to copy a surface to an other surface with alpha value?



flyaflya wrote:

> I want to join some surfaces to a new big surface with alpha cannel, I
> want the new surface has same pixels(inclue r,g,b and alpha value) as
> the pixels on the source surfaces.
> my code as follow:
> surf = pygame.Surface((200,200))
> surf.blit(surf1, (0,0))
> surf.blit(surf2, (0,100))
> .....
> but these codes can't copy alpha value to the new surface.how can I
> deal with it?

Your code creates surf in RGB format, and thus surf1 and surf2 are
"cast" from RGBA to RGB when blitted onto surf. One way around this is
to convert surf to RGBA, e.g.

surf = pygame.Surface((200,200)).convert_alpha()
surf.blit(surf1, (0,0))
surf.blit(surf2, (0,100))

There's probably a faster way to do this without the conversion step,
but unless you're doing this repeatedly this shouldn't be a problem.

-Jasper