Pixel-perfect collision with scale/rotation (transforms match rendering, expensive ~5-50ms, stores collision point).
Takes image1/2 (handles), x1/y1/x2/y2 (positions), scaleX1/Y1/X2/Y2 (scale factors, doubles, 1.0=normal), rotation1/2 (degrees, doubles).
Returns 1 if non-transparent pixels overlap, 0 if no collision.
2D Overlay
Parameters & Returns
Parameters
image1Int
x1Int
y1Int
scaleX1Double
scaleY1Double
rotation1Double
image2Int
x2Int
y2Int
scaleX2Double
scaleY2Double
rotation2Double
Returns
Int
Quick Summary
Pixel-perfect collision with scale/rotation (transforms match rendering, expensive ~5-50ms, stores collision point).
Takes image1/2 (handles), x1/y1/x2/y2 (positions), scaleX1/Y1/X2/Y2 (scale factors, doubles, 1.0=normal), rotation1/2 (degrees, doubles).
Returns 1 if non-transparent pixels overlap, 0 if no collision.
Technical Exegesis...
Pixel-perfect collision with scale/rotation (transforms match rendering, expensive ~5-50ms, stores collision point). Takes image1/2 (handles), x1/y1/x2/y2 (positions), scaleX1/Y1/X2/Y2 (scale factors, doubles, 1.0=normal), rotation1/2 (degrees, doubles). Returns 1 if non-transparent pixels overlap, 0 if no collision.
Pixel-perfect collision with scale/rotation (transforms match rendering, expensive ~5-50ms, stores collision point). Takes image1/2 (handles), x1/y1/x2/y2 (positions), scaleX1/Y1/X2/Y2 (scale factors, doubles, 1.0=normal), rotation1/2 (degrees, doubles). Returns 1 if non-transparent pixels overlap, 0 if no collision. Calculates transformed bounding boxes (accounts for scale/rotation, early-reject if don't overlap), iterates image1 texture pixels (for each non-transparent pixel in image1), forward transform to world space (scale -> rotate around center -> translate), inverse transform to image2 space (world -> image2 local -> check if alpha>0), stores collision point (first overlap pixel in world coordinates). Use for rotating sprites (asteroids, player ship), scaled enemies (growing/shrinking), physics simulation with arbitrary orientations. Algorithm complexity: downloads pixel data (~1-10ms per image), calculates rotation matrices (cos/sin for both images), AABB test with rotated corners (8 corners -> min/max bounding box), iterates all image1 pixels (~width1xheight1 iterations), each pixel: forward transform (scale+rotate) -> inverse transform image2 (rotate+unscale) -> bounds check + alpha test, worst case O(width1xheight1) pixel tests. Performance expensive: GPU readback (~2-20ms for both images), transform calculations (matrix math per pixel, ~5-30ms depending on image sizes), total ~5-50ms per collision test, much slower than Simple version, use sparingly (not every frame for many objects). Transform math matches rendering: handle offset (actualX = x - int(handleXxscaleX)), rotation center (middle of scaled sprite), rotation order (scale -> rotate -> translate), degrees to radians (rotation x pi/180), inverse transform (unrotate = rotate by -angle, unscale = divide by scale). Use cases: (1) Rotating collision (If b2dIsImagesColliding(ship,sx,sy,1,1,shipAngle, asteroid,ax,ay,1,1,astAngle) Then hit), (2) Scaled sprites (If b2dIsImagesColliding(player,px,py,1,1,0, boss,bx,by,bossScale,bossScale,0) Then collision), (3) Full transform (If b2dIsImagesColliding(obj1,x1,y1,sc1X,sc1Y,rot1, obj2,x2,y2,sc2X,sc2Y,rot2) Then both transformed). Optimization: broad-phase first (use b2dIsCirclesColliding or b2dIsBoxesColliding approximation, only call this if cheap test suggests possible collision), limit frequency (don't test every frame, test every N frames or on state changes), cache pixel data (lock images if testing multiple times). Collision point: world space coordinates (where first overlap pixel detected in screen/world space), retrieve with b2dGetImageCollisionX/Y (after collision detected), useful for effects (spawn particle/sound at collision point). Limitations: very expensive (5-100x slower than Simple version), prefer Simple when no rotation/scale needed, consider circular/box approximations for gameplay collision (reserve pixel-perfect for critical accurate tests). Related: b2dIsImagesCollidingSimple (no scale/rotation, much faster), b2dGetImageCollisionX/Y (retrieves collision point), b2dLockImage (can pre-lock for optimization), b2dIsCirclesColliding (fast approximation for broad-phase).