views:

125

answers:

1

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?

+1  A: 

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!

Shirkrin
I'm thinking I'll just subclass pygame.Surface - seems like the easiest solution.
Smashery