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

Re: [pygame] Determining whether a Pixel in a Sprite is Transparent?



Steven M. Castellotti wrote:
> 	I want to take a user's mouse click coordinates, and use it to
> determine whether or not a user clicked on a particular image, taking
> transparency at the corners into mind.

this won't be difficult. you'll need to deal with the fact pygame 
can do transparancy with colorkeys or with per pixel alpha. let's 
see if i can come up with some mojo..


def collide_surface(image, pos):
     'return true if pixel at pos is solid'
     try:
         pix = image.get_at(pos)
     except IndexError:
         return 0
     if pix == image.get_colorkey():
         return 1
     return pix[3] > 4


this should take into account nearly any type of settings for a 
surface. it will even handle cases where "pos" is outside the image. 
that should save you from even needing to check the boundingbox :]


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