[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] Transparancy



> I initialized a surface this way:
> 
>     box1=pygame.Surface((50,50),HWSURFACE|SRCALPHA,32)
> 
> and filled it like this:
> 
>     box1.fill((128,128,0,128))
> 
> I end up with a fully opaque box.  I tried different
> display bit depths and combinations of fullscreen,
> windowed, and doublebuffered flags as well as
> hardware and software surfaces.  None would yield
> transparency.

hi andy. there are a couple extra steps to get transparancy
going. i'll toss up a quick intro here.

there are two types of transparancy for surfaces. (well, if you
count colorkeying there are sort of 3, but this is different)

first, there is an overall image transparancy. this is the best
way to go if you image will be all a consistent transparancy,
it can also be mixed with colorkeying.

second, there is 'per-pixel-alphas', these are done by creating
a surface with specific alpha channels. this is done by either
loading from an image that supports alpha channels (like PNG),
or creating a surface with specific alpha channels.


to set an overall transparancy for an image:
mysurface.set_alpha(128)

to create a surface with an alpha channel:
masks = 0xff<<16, 0xff<<8, 0xff, 0xff<<24
mysurface = pygame.Surface((50, 50), SRCALPHA, masks)


the problem is that the Surface constructor only guesses
at some standard color masks when you specify a bit depth.
i should make it smarter, so that if it sees SRCALPHA as
one of the requested flags it creates masks that have an
alpha channel. i will add this in the next release, but for
now you'll need to do it this way.

(hope this works right, sorry i didn't have time to
doublecheck my little commands here)


____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org