开发者

can you make an image transparent over another image in pygame? [duplicate]

This question already has an answer here: Pygame image transparency confusion (1 answer) Closed 2 months ago.

I'm able to set an image to be transparent using the both the set_col开发者_C百科orkey method and the convert_alpha method over a surface background. However, when I try to overlap two images the transparency is lost for some reason.

So to reiterate, is there a way to make part of an image transparent over another image (e.g. two png or gif files)


I'm not sure if you're running into "buggy" behavior or not. It is possible color-key alpha doesn't support what you are trying to do, and it is possible that you are either defining your pixel data wrong, or that there is some sort of bug (video driver or pygame) that you're experiencing.

But I do have a work-around for you:

http://www.pygame.org/docs/ref/surface.html

There are three types of transparency supported in Pygame: colorkeys, surface alphas, and pixel alphas

You could try pixel alphas. It will be more flexible than color-key alpha, and should support blending as many layers as you want.

You can do this by passing SRCALPHA when creating the surface, and ensuring that your input pixel data has a properly defined alpha channel.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜