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

Re: [pygame] Howto blit a mask



Hi Peter, It works!!

Thanks so much.
CC

On 6/3/06, Peter Shinners <pete@xxxxxxxxxxxx> wrote:
On Fri, 2006-06-02 at 23:56 -0400, Chuang Wu wrote:
> when I click on the image, I wanna add a light yellow mask on it, so
> we can still see the image, with a half-transparent cover. And if I
> re-click, the mask is removed.
>
> Could I just use blit() to do this?

You'll want to use two images and switch between them. There's a few
ways to generate the yellow version of the image. The most generic would
be to blit a slightly transparent yellow image on top of yours.

def YellowImage(originalSurface):
    yellowSurface = originalSurface.copy ()
    yellow = pygame.Surface(yellowSurface.size())
    yellow.fill(pygame.Color("yellow"))
    yellow.set_alpha(128)
    yellowSurface.blit(yellow, (0, 0)
    return yellowSurface

You could also use Surfarray to change the color values of the pixels.
This will give you a better look, but will also require a dependency
Numeric.