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

Re: [pygame] Masking Test: Simulated Lighting (Follow-Up)



Kris Schnee wrote:
Kamilche wrote:
Try the following code. It uses a gradient light.

I'm trying to figure out how your example (much better than mine) works. It looks like the key is the last line of this function:


def RefreshNight(night, alpha, light, x, y):
a = NIGHTCOLOR[3]
alpha.fill([a, a, a])
r = LIGHTSIZE/2
alpha.blit(light, [x-r, y-r])
pygame.surfarray.pixels_alpha(night)[:, :] = pygame.surfarray.pixels2d(alpha)

So, to get around the problem of a pre-drawn lightmask not getting properly put onto the dark mask, you're using the surfarray module to address the alpha channel of the dark mask directly? Is that how this works? I don't recognize the [:,:] syntax -- a list containing two copies of a list, maybe.


I tried using a version of that line instead of directly blitting my lightmask onto dark, but Python complained that it couldn't safely cast the array. I guess there's some trick to how the surfaces are defined, but I haven't been able to figure it out yet.

Kris



The easiest way to grok it, is to save the image of the gradient I create in the CreateLight function.

That last line copies the picture of the grayscale light gradient plus desired night level, to the alpha channel of the final nighttime picture. The color never changes on the nighttime picture - just the alpha channel.

--Kamilche