Question

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. 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?

Was it helpful?

Solution

Considering the pygame docs I would say "no, there is no global way to disable 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.

  • Second one is a bit more tricky as it depends on the pixel-format in use. To quote the pygame docs:

Surface.set_alpha
set the alpha value for the whole surface
[...]
This value is different than the per pixel Surface alpha. If the Surface format contains per pixel alphas, then this alpha value will be ignored. If the Surface contains per pixel alphas, setting the alpha value to None will disable the per pixel transparency.
[...]

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()
  • one which has no per-pixel alpha and thus will honor your set_alpha()

Hope this will help!

OTHER TIPS

I have read that the convert()-function disables image's 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.

image = image.convert()#video system has to be initialed
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top