pygame documentation | || Pygame Home || Help Contents || Reference Index || Cdrom || 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

pygame module for image masks.

pygame.mask.pygame.mask.from_surface - Returns a Mask from the given surface. | Returns a Mask from the given surface.
pygame.mask.pygame.Mask - pygame object for representing 2d bitmasks | pygame object for representing 2d bitmasks
pygame.mask.get_size - Returns the size of the mask. | Returns the size of the mask.
pygame.mask.get_at - Returns nonzero if the bit at (x,y) is set. | Returns nonzero if the bit at (x,y) is set.
pygame.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.
pygame.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.
pygame.mask.overlap_area - Returns the number of overlapping 'pixels'. | Returns the number of overlapping 'pixels'.
pygame.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.

Useful for fast pixel perfect collision detection. `A` Mask uses 1bit per pixel to store which parts collide.

New in pygame `1.8`.

pygame.mask.pygame.mask.from_surface

Returns a Mask from the given surface.
`pygame.mask.from_surface(Surface, threshold = 127) -> Mask`

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.

pygame.mask.pygame.Mask

pygame object for representing 2d bitmasks
`pygame.Mask((width, height): return Mask`

pygame.mask.get_size

Returns the size of the mask.
`Mask.get_size() -> width,height`

pygame.mask.get_at

Returns nonzero if the bit at (x,y) is set.
`Mask.get_at((x,y)) -> int`

Coordinates start at (0,0) is top left - just like Surfaces.

pygame.mask.set_at

Sets the position in the mask given by x and y.
`Mask.set_at((x,y),value)`

pygame.mask.overlap

Returns the point of intersection if the masks overlap with the given offset - or None if it does not overlap.
`Mask.overlap(othermask, offset) -> x,y`

The overlap tests uses the following offsets (which may be negative):

       +----+----------..
       |A   | yoffset
       |  +-+----------..
       +--|B
       |xoffset
       |  |
       :  :

pygame.mask.overlap_area

Returns the number of overlapping 'pixels'.
`Mask.overlap_area(othermask, offset) -> numpixels`

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.

pygame.mask.get_bounding_rects

Returns a list of bounding rects of regions of set pixels.
`Mask.get_bounding_rects() -> Rects`

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.