[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Mixing Colorkey and Surface alpha



On Wed, Feb 29, 2012 at 12:23 PM, Lin Parkh <lparkh@xxxxxxxxxxx> wrote:

I have two surfaces. The source surface that I am blitting has a “surface alpha” set to give me semi transparency.  The destination surface has a transparent colorkey.  What I would like to have happen is that source surface makes semi transparent any pixels on the destination surface that are not transparent but otherwise ignores the colorkey pixels.  Is this possible?

As far as I am aware, and the way you're asking, no.  If you think about it, the destination surface is has binary transparency values (i.e., completely opaque or completely transparent).  What sort of data would you expect to store to get a semi-transparent colorkeyed surface?

My recommendation is to just use per-pixel alpha for just about everything.  You can pretty easily convert a colorkeyed surface into one.  At a guess, I would appreciate if the designers made .convert_alpha() do this--but if they didn't, the conversion would be pretty simple: loop through all pixels in the old surface, set the new surface's corresponding pixel's transparency to be either 0 or 255 based on what the RGB color is.  If you do this, then the blending operation you described above suddenly becomes trivial.

Ian