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

Re: [pygame] Setting alpha with a blit?



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.

This works pretty well actually, as long as you don't need antialiasing or semitransparent pixels. If you want to control true alpha transparency, you'll probably want to use the surfarray to manually control the pixel values. Of course, loading the alpha on from a file is a good idea too.

For examples of the colorkey masking, see some of the old Font Contest entries, where Font.render() is used to create masks on some sort of pattern.

http://www.pygame.org/pcr/progress_text/index.php
http://www.pygame.org/pcr/static_text/index.php