Pixel-perfect collision (no scale/rotation, AABB early-reject + alpha overlap test, stores collision point).
Takes image1,image2 (image handles, integers), x1,y1,x2,y2 (image positions accounting for handles, integers).
Returns 1 if non-transparent pixels overlap, 0 if no collision.
2D Overlay
Parameters & Returns
Parameters
image1Int
x1Int
y1Int
image2Int
x2Int
y2Int
Returns
Int
Quick Summary
Pixel-perfect collision (no scale/rotation, AABB early-reject + alpha overlap test, stores collision point).
Takes image1,image2 (image handles, integers), x1,y1,x2,y2 (image positions accounting for handles, integers).
Returns 1 if non-transparent pixels overlap, 0 if no collision.
Technical Exegesis...
Pixel-perfect collision (no scale/rotation, AABB early-reject + alpha overlap test, stores collision point). Takes image1,image2 (image handles, integers), x1,y1,x2,y2 (image positions accounting for handles, integers). Returns 1 if non-transparent pixels overlap, 0 if no collision.
Pixel-perfect collision (no scale/rotation, AABB early-reject + alpha overlap test, stores collision point). Takes image1,image2 (image handles, integers), x1,y1,x2,y2 (image positions accounting for handles, integers). Returns 1 if non-transparent pixels overlap, 0 if no collision. AABB early-reject (b2dIsBoxesColliding for bounding boxes, skips pixel test if boxes don't overlap), downloads pixel data from GPU (GetOverlayImagePixelData for both images), tests overlap region (for each pixel in overlap: check if both alpha>0), stores collision point (g_2D_lastImageCollisionX/Y = first collision pixel found), GPU readback cost (~1-10ms depending on image sizes). Use for exact sprite collision (complex shapes, irregular sprites), platformer games (player-enemy/player-platform collision), pixel art games (where shape matters). Algorithm: calculate actual positions (x1-handleX1, y1-handleY1), AABB test (if bounding boxes don't overlap, return 0 immediately), overlap region (intersection of two bounding boxes), pixel loop (for each pixel in overlap: get alpha from both images, if both alpha>0 then collision), early exit (returns 1 on first collision pixel found). Use cases: (1) Player-enemy collision (If b2dIsImagesCollidingSimple(playerImg,playerX,playerY, enemyImg,enemyX,enemyY) Then hit), (2) Platformer collision (If b2dIsImagesCollidingSimple(player,px,py, platform,platX,platY) Then onGround), (3) Pickup detection (If b2dIsImagesCollidingSimple(player,px,py, item,ix,iy) Then collect), (4) Projectile hit (If b2dIsImagesCollidingSimple(bullet,bx,by, target,tx,ty) Then destroy). Performance: AABB early-reject fast (~0.0001ms if no overlap), pixel test expensive (GPU readback ~1-10ms for each image, pixel loop ~0.01-1ms depending on overlap size), total cost ~2-20ms per collision test. Optimization: broad-phase (use b2dIsCirclesColliding or b2dIsBoxesColliding first, only call this if cheap test passes), cache pixel data (call b2dLockImage once, reuse buffer for multiple collision tests avoids GPU readback), limit tests (don't test every object pair, use spatial partitioning). Handle awareness: respects image handles (x,y positions affected by handleX/handleY, actualX = x - handleX), accounts for pivot (handles set via b2dSetImageHandle or b2dSetImageMidHandle), consistent with rendering (collision position matches draw position). Collision point: stored globally (g_2D_lastImageCollisionX/Y updated on collision), query with b2dGetImageCollisionX/Y (retrieve after collision detected), world space coordinates (pixel position in screen/world space where first overlap detected), first pixel found (not center or weighted average, deterministic first match in overlap scan). Limitations: no rotation (images must be axis-aligned, rotated sprites not supported), no scale (images at original size, scaled sprites not supported), use b2dIsImagesColliding for rotation/scale support (slower but handles transformations). Related: b2dIsImagesColliding (supports scale/rotation, much slower), b2dGetImageCollisionX/Y (retrieves collision point after detection), b2dLockImage (can optimize by pre-locking images), b2dIsBoxesColliding (used internally for AABB early-reject).