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

Re: [pygame] Setting alpha with a blit?



On Thu, 17 Jun 2004, Pete Shinners wrote:

> Jasper Phillips wrote:
> > I have a surface to which I want to add hex shaped transparent holes, with
> > the aim of creating a "frame" that I can blit onto a hex map to mask
> > anything outside the hexes.
> > 
> > Is there some api or trick for doing this?
> 
> The only tricky way to do this is with colorkeys. If you have a two 
> color image, you set the colorkey to the 'interior' color and blit that 
> on top of the image to mask. Then on that image you set the colorkey to 
> the remaining color.

Thanks, colorkey was exactly what I needed!  I've done similar tricks with
palette swapping, but wasn't aware of colorkey.  I'm glad I asked before
falling back on palette swapping. :-)

One odd point I came across that led me to at first suspect colorkey wasn't
working:  I load a hex image with transparent corners from a file, and then
repeatedly blit that onto a surface to create a hex map.  I tried using the
color from the hex image as the colorkey -- but this failled!  It turns out
the surface had a different color than the source image it was constructed
from, with the RGB values all reduced by 1 (alpha stayed at 255)...

Presumably a bug?

-Jasper