Mask
A 2D binary mask for pixel-perfect collision detection and pixel manipulation.
-
Mask()
-
Mask(size: Vec2, filled: bool = False)
-
Mask(pixel_array: PixelArray, threshold: int = 1)
Properties
Name | Description | Type |
---|---|---|
width | The width of the mask | int |
height | The height of the mask | int |
size | The size of the mask | Vec2 |
Methods
Clear
clear() → None
Clear the mask, setting all values to False.
Fill
fill() → None
Fill the mask, setting all values to True.
Add
add(other: Mask, offset: Vec2 = None) → None
Add another mask to this mask.
Parameters
other
: The other mask to add.
Subtract
subtract(other: Mask, offset: Vec2 = None) → None
Subtract another mask from this mask.
Parameters
other
: The other mask to subtract.
Invert
invert() → None
Invert the mask, flipping all values.
Is Empty
is_empty() → bool
Check if the mask is empty (all values are False).
Returns
bool
: True if the mask is empty, False otherwise.
Get Rect
get_rect() → Rect
Get a rectangle defining the width and height of the mask.
Returns
Rect
: The rectangle defining the mask area.
Set At
set_at(pos: Vec2, value: bool) → None
Set the value at a specific position in the mask.
Parameters
pos
: The position to set the value at.value
: The value to set.
Get At
get_at(pos: Vec2) → bool
Get the value at a specific position in the mask.
Parameters
pos
: The position to get the value from.
Returns
bool
: The value at the specified position.
Get Count
get_count() → int
Get the count of True values in the mask.
Returns
int
: The number of True values in the mask.
Get Bounding Rect
get_bounding_rect() → Rect
Get the bounding rectangle of the mask.
Returns
Rect
: The bounding rectangle of the mask.
Get Center of Mass
get_center_of_mass() → Vec2
Get the center of mass of the mask.
Returns
Vec2
: The center of mass of the mask.
Get Collision Points
get_collision_points(other: Mask, offset: Vec2 = None) → list[Vec2]
Get the collision points between this mask and another mask.
Returns
list[Vec2]
: The list of collision points.
Get Outline
get_outline() → list[Vec2]
Get the outline points of the mask.
Returns
list[Vec2]
: The list of outline points.
Get Overlap Area
get_overlap_area(other: Mask, offset: Vec2 = None) → int
Get the overlap area (number of pixels) between this mask and another mask.
Returns
int
: The overlap area.
Get Overlap Mask
get_overlap_mask(other: Mask, offset: Vec2 = None) → Mask
Get the overlap mask between this mask and another mask.
Returns
Mask
: The overlap mask.
Get Pixel Array
get_pixel_array() → PixelArray
Create a pixel array out of the mask.
Returns
PixelArray
: The pixel array from the mask.
Copy
copy() → Mask
Create a copy of the mask.
Returns
Mask
: The copied mask.