简体   繁体   English

关闭Pygame Alpha

[英]Turn off Pygame alpha

I have a computer game I'm working on, and I'm wanting to give the user an option to turn off alpha compositing for speed purposes. 我正在开发一款电脑游戏,并且我想为用户提供一个选项,以便出于速度目的而关闭Alpha合成。 Rather than doing checks everywhere, does Pygame have a global option to say "Don't use alpha" such that it would just ignore all my calls to set_alpha and the likes? Pygame不会在所有地方进行检查,而是有一个全局选项说“不要使用alpha”,这样它就只会忽略我对set_alpha之类的所有调用?

Considering the pygame docs I would say "no, there is no global way to disable alpha" . 考虑到pygame文档,我会说“不,没有禁用alpha的全局方法”
However there are at least two 'local' ways to do it: 但是,至少有两种“本地”方式可以做到这一点:

  • First would be to subclass pygame.Surface and provide your own implementation of set_alpha which in turn could honor your global alpha settings. 首先是pygame.Surface的子类,并提供您自己的set_alpha实现,从而可以使用全局alpha设置。

  • Second one is a bit more tricky as it depends on the pixel-format in use. 第二个有点棘手,因为它取决于使用的像素格式。 To quote the pygame docs: 引用pygame文档:

Surface.set_alpha Surface.set_alpha
set the alpha value for the whole surface 设置整个表面的Alpha值
[...] [...]
This value is different than the per pixel Surface alpha. 此值不同于每个像素的表面alpha。 If the Surface format contains per pixel alphas, then this alpha value will be ignored. 如果“表面”格式包含每个像素的Alpha,则将忽略此Alpha值。 If the Surface contains per pixel alphas, setting the alpha value to None will disable the per pixel transparency. 如果“曲面”包含按像素的Alpha,则将Alpha值设置为“无”将禁用按像素的透明度。
[...] [...]

With this you could provide two sets of textures: 通过此操作,您可以提供两组纹理:

  • one with an opaque (per-pixel) alpha channel which will overwrite all your calls to set_alpha() 一个具有不透明(每像素)alpha通道的控件 ,它将覆盖您对set_alpha()的所有调用
  • one which has no per-pixel alpha and thus will honor your set_alpha() 一个没有每个像素的Alpha,因此将尊重您的set_alpha()

Hope this will help! 希望这会有所帮助!

I have read that the convert()-function disables image's alpha. 我已经读过convert()函数禁用图像的Alpha。 What I know is: 我所知道的是:

Using the convert()-function speeds up blitting the image for screen-big images on my computer to around 150 FPS with a colour depth of 16 bit. 使用convert()函数可将计算机上屏幕较大的图像的图像提速到150 FPS,色深为16位。

image = image.convert()#video system has to be initialed

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM