![]() pygame documentation |
||
Pygame Home ||
Help Contents ||
Reference Index ||
Cdrom || Color || Cursors || Display || Draw || Event || Font || Image || Joystick || Key || Mask || Mixer || Mouse || Movie || Music || Overlay || Pixelarray || Pygame || Rect || Scrap || Sndarray || Sprite || Surface || Surfarray || Time || Transform |
pygame.mask.from_surface - Returns a Mask from the given surface. | Returns a Mask from the given surface. |
pygame.mask.Mask - pygame object for representing 2d bitmasks | pygame object for representing 2d bitmasks |
Useful for fast pixel perfect collision detection. A Mask uses 1bit per pixel to store which parts collide.
New in pygame 1.8.
Makes the transparent parts of the Surface not set, and the opaque parts set.
The alpha of each pixel is checked to see if it is greater than the given threshold.
If the Surface is color keyed, then threshold is not used.
Mask.get_size - Returns the size of the mask. | Returns the size of the mask. |
Mask.get_at - Returns nonzero if the bit at (x,y) is set. | Returns nonzero if the bit at (x,y) is set. |
Mask.set_at - Sets the position in the mask given by x and y. | Sets the position in the mask given by x and y. |
Mask.overlap - Returns the point of intersection if the masks overlap with the given offset - or None if it does not overlap. | Returns the point of intersection if the masks overlap with the given offset - or None if it does not overlap. |
Mask.overlap_area - Returns the number of overlapping 'pixels'. | Returns the number of overlapping 'pixels'. |
Mask.get_bounding_rects - Returns a list of bounding rects of regions of set pixels. | Returns a list of bounding rects of regions of set pixels. |
Coordinates start at (0,0) is top left - just like Surfaces.
The overlap tests uses the following offsets (which may be negative):
+----+----------.. |A | yoffset | +-+----------.. +--|B |xoffset | | : :
You can see how many pixels overlap with the other mask given. This can be used to see in which direction things collide, or to see how much the two masks collide.
This gets a bounding rect of connected regions of set pixels. A bounding rect is one for which each of the connected pixels is inside the rect.