Tests axis-aligned bounding box (AABB) collision (fastest collision test, no rotation, edge/corner inclusive).
Takes box1Left,box1Right,box1Top,box1Bottom (first rectangle bounds, integers), box2Left,box2Right,box2Top,box2Bottom (second rectangle bounds, integers).
Returns 1 if boxes overlap or touch, 0 if separated.
2D Overlay
Parameters & Returns
Parameters
box1LeftInt
box1RightInt
box1TopInt
box1BottomInt
box2LeftInt
box2RightInt
box2TopInt
box2BottomInt
Returns
Int
Quick Summary
Tests axis-aligned bounding box (AABB) collision (fastest collision test, no rotation, edge/corner inclusive).
Takes box1Left,box1Right,box1Top,box1Bottom (first rectangle bounds, integers), box2Left,box2Right,box2Top,box2Bottom (second rectangle bounds, integers).
Returns 1 if boxes overlap or touch, 0 if separated.
Technical Exegesis...
Tests axis-aligned bounding box (AABB) collision (fastest collision test, no rotation, edge/corner inclusive). Takes box1Left,box1Right,box1Top,box1Bottom (first rectangle bounds, integers), box2Left,box2Right,box2Top,box2Bottom (second rectangle bounds, integers). Returns 1 if boxes overlap or touch, 0 if separated.
Tests axis-aligned bounding box (AABB) collision (fastest collision test, no rotation, edge/corner inclusive). Takes box1Left,box1Right,box1Top,box1Bottom (first rectangle bounds, integers), box2Left,box2Right,box2Top,box2Bottom (second rectangle bounds, integers). Returns 1 if boxes overlap or touch, 0 if separated. Tests X overlap (box1Left <= box2Right AND box1Right >= box2Left), tests Y overlap (box1Top <= box2Bottom AND box1Bottom >= box2Top), collision if both X and Y overlap (inclusive test, touching edges = collision). Use for fast broad-phase collision, rectangular objects, trigger zones, grid-based collision, early rejection before expensive pixel-perfect tests. AABB algorithm: separating axis theorem simplified for axis-aligned rectangles, checks if no gap exists on X-axis and Y-axis, fastest possible 2D collision test, exact for rectangles (not approximation). Use cases: (1) Rectangle collision (left1=x1: right1=x1+w1: top1=y1: bottom1=y1+h1: calculate box2 bounds: If b2dIsBoxesColliding(...) Then collision), (2) Trigger zone (If b2dIsBoxesColliding(playerLeft,playerRight,playerTop,playerBottom, zoneLeft,zoneRight,zoneTop,zoneBottom) Then entered), (3) Broad-phase (If b2dIsBoxesColliding(bounds1, bounds2) Then b2dIsImagesColliding(img1, img2) two-phase detection), (4) Grid collision (For each cell: If b2dIsBoxesColliding(objectBounds, cellBounds) Then inCell), (5) UI hit testing (If b2dIsBoxesColliding(mouseX,mouseX,mouseY,mouseY, buttonLeft,buttonRight,buttonTop,buttonBottom) Then clicked). Common patterns: bounds from position = left=x: right=x+width: top=y: bottom=y+height; point test = b2dIsBoxesColliding(px,px,py,py, left,right,top,bottom) point inside rectangle. Performance: cost minimal (~6 integer comparisons, ~0.00005ms per call, fastest collision test available), no multiplications or sqrt (pure comparisons), thousands per frame (suitable for broad-phase collision of many objects). Axis-aligned only: rectangles must be axis-aligned (sides parallel to X/Y axes, no rotation support), rotated objects incorrect (use b2dIsImagesColliding for rotated collision), trade-off (speed vs rotation, AABB approximates rotated objects as larger axis-aligned box). Coordinate system: left < right (left edge X < right edge X), top < bottom (top edge Y < bottom edge Y, Y increases downward), inclusive (touching edges return 1 collision, use < for exclusive if needed). Related: b2dIsCirclesColliding (circular bounds, slower but rotation-invariant), b2dIsCircleBoxColliding (hybrid circle-rectangle), b2dIsImagesColliding (pixel-perfect with rotation support, much slower), b2dIsImagesCollidingSimple (AABB test + pixel-perfect, uses this function internally for early rejection).