[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.
Numeric, and kin, support multidimensional arrays directly. Indices are
comma separated in the get item operator. pixels_alpha() returns a
two-dimensional array. For an m by n array, [:, :] is the same as [0:m,
0:n], or for each row 0 to (n-1) of each column 0 to (m-1). An ellipsis,
[...] , can also be used and is dimension independent.
--
Lenard Lindstrom
<len-l@xxxxxxxxx>