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

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



Hey all--

	I've been doing quite of bit of work with Pygame over the past few
weeks, and so far it's been a joy to learn. I've become a little stuck
on something however:

	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.



	Currently, I've created a "layered_graphic_panel" class which takes
graphics filename and their coordinates passed to it, loads the sprite,
blits it at the appropriate coordinates, and then keeps track of
information such as the filename, coordinates, rect of the image, etc. -
stored in a dictionary, and appended to a list of "layers"

	When I want to figure out which image a user clicked on, the class will
start looking at each layer (from the top/last layer on down), and check
to see if the mouse click fell into the coordinates of the sprite's
rect. If so, it returns the information about the image.

	This all works great, but I want to take it one step further. I want to
check to make sure that the portion of the sprite the user clicked on
isn't transparent. When working with png's and gif's it's pretty easy to
make the edges of a sprite transparent, but now I want to determine that
through pygame.


	I couldn't find anything in the documentation that mentioned how to do
this on a per-pixel level. Is there an easy way to do this that I'm
overlooking?


Cheers,

Steve Castellotti
SteveC@innocent.com
http://cogengine.sourceforge.net/



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