PyGame:具有每像素 alpha 的半透明精灵 [英] PyGame: translucent sprites with per pixel alpha

查看:51
本文介绍了PyGame:具有每像素 alpha 的半透明精灵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以显示具有可控 alpha 的 PyGame 表面?我想用自己的每像素 alpha 显示一个表面,并在不影响表面数据的情况下以可变的半透明级别显示它并保持透明度不变,即表面上的对象会保持它们的形状,但它们的内容"或多或少半透明.

Is it possible to display PyGame surfaces with controllable alpha? I would like to take a surface with its own per pixel alpha and display it with variable level of translucency without affecting the surface data and keep the transparency intact i.e. the objects on the surface would keep their shapes but their "contents" becoming more or less translucent.

换句话说,我想将源图像的每像素 alpha 与在运行时计算的每表面 alpha 结合起来.

In other words I want to combine per-pixel alpha from the source image with per-surface alpha calculated at the runtime.

推荐答案

在检查 PyGame 和 SDL 文档后,我得出的结论是,我所要求的在 PyGame 中使用标准函数是不可行的.

After checking both PyGame and SDL documentations I came to conclusion that what I asked wasn't doable in PyGame using standard functions.

SDL 文档指出,每像素 alpha 和每表面 alpha 不能与前者相结合,前者总是优先.实现我想要的效果的唯一方法是编写一个代码,在 blit 之前更新源表面的每像素 alpha 值.

SDL docs state that per-pixel alpha and per-surface alpha cannot be combined with the former always taking the precedence. The only way to achieve the effect I want is by writing a code which updates per-pixel alpha values of the source surface before the blit.

这篇关于PyGame:具有每像素 alpha 的半透明精灵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆