你能在pygame中使一个图像在另一个图像上透明吗?
我可以在表面背景上使用 set_colorkey
方法和 convert_alpha
方法将图像设置为透明。但是,当我尝试重叠两个图像时,由于某种原因透明度会丢失。
所以重申一下,有没有办法使图像的一部分在另一个图像上透明(例如两个 png 或 gif 文件)
I'm able to set an image to be transparent using the both the set_colorkey
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您是否遇到了“错误”行为。颜色键 alpha 可能不支持您想要执行的操作,并且您可能定义了错误的像素数据,或者存在某种错误(视频驱动程序或 pygame)正在经历。
但我确实为您提供了解决方法:
http://www.pygame.org/文档/ref/surface.html
您可以尝试像素 alpha。它比颜色键 Alpha 更灵活,并且应该支持混合任意数量的图层。
您可以通过在创建表面时传递
SRCALPHA
来实现此目的,并确保您的输入像素数据具有正确定义的 Alpha 通道。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
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.