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

Re: [pygame] Problems with surfarrays



Peter Thoman wrote:

> I recently played around with per-pixel alpha and now tried to make a whole
> image transparent while keeping its relative alpha values. So I came up with
> this code:

 >

> The second line looks like intended, but what happens then? If anybody could
> shed some light on this I'd be grateful.

support for alpha was kind of added on afterwards for the surfarray 
module. unfortunately support for alphas isn't quite as strong as for 
regular rgb.

the blit_array function you are trying to use only copies arrays with 
color into a surface.

the good news is, you should be able to do what you want with the 
surfarray module. when you want to 'interact' with the alpha channel, 
the only way to do it is be getting an array from pixels_alpha (this 
only works for 32bit surfaces). the pixels_alpha array directly 
references the alpha values in the Surface. so changing the array 
changes the pixels.

your function would become something like this:

   alphaarray=pygame.surfarray.pixel_alpha(self.surface)
   temparray=alphaarray*(color[3]/255)
   alphaarray[:]=temparray.astype(Int)

that last line copies all the values from temparray into the alphaarray.

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