Methods
imagesCollide(img1, x1, y1, frame1opt, img2, x2, y2, frame2opt, alphaThresholdopt) → {boolean}
Checks for pixel-perfect collision between two images, correctly handling translation, scaling, and rotation.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
img1 |
Jmage | The first image object. | ||
x1 |
number | The x-coordinate of the first image's handle. | ||
y1 |
number | The y-coordinate of the first image's handle. | ||
frame1 |
number |
<optional> |
1 | The frame number for the first image. |
img2 |
Jmage | The second image object. | ||
x2 |
number | The x-coordinate of the second image's handle. | ||
y2 |
number | The y-coordinate of the second image's handle. | ||
frame2 |
number |
<optional> |
1 | The frame number for the second image. |
alphaThreshold |
number |
<optional> |
128 | The alpha value (0-255) above which a pixel is considered solid. |
- Source:
Returns:
True if any solid pixels overlap, false otherwise.
- Type
- boolean
imagesOverlap(img1, x1, y1, img2, x2, y2) → {boolean}
Checks if two images, placed at specific coordinates, overlap based on their bounding boxes.
This check correctly handles scaled and rotated images by calculating their axis-aligned bounding box.
Parameters:
| Name | Type | Description |
|---|---|---|
img1 |
Jmage | The first image object. |
x1 |
number | The x-coordinate of the first image's handle. |
y1 |
number | The y-coordinate of the first image's handle. |
img2 |
Jmage | The second image object. |
x2 |
number | The x-coordinate of the second image's handle. |
y2 |
number | The y-coordinate of the second image's handle. |
- Source:
Returns:
True if the images' bounding boxes overlap, false otherwise.
- Type
- boolean
rectsOverlap(x1, y1, w1, h1, x2, y2, w2, h2) → {boolean}
Checks if two axis-aligned rectangles overlap.
Parameters:
| Name | Type | Description |
|---|---|---|
x1 |
number | X-coordinate of the first rectangle. |
y1 |
number | Y-coordinate of the first rectangle. |
w1 |
number | Width of the first rectangle. |
h1 |
number | Height of the first rectangle. |
x2 |
number | X-coordinate of the second rectangle. |
y2 |
number | Y-coordinate of the second rectangle. |
w2 |
number | Width of the second rectangle. |
h2 |
number | Height of the second rectangle. |
- Source:
Returns:
True if the rectangles overlap, false otherwise.
- Type
- boolean