# AS3 Rect-Rect Collision

Basically, my game has the player's attack hitbox change based on the attack being performed. I tried to make a simple collision test that takes an enemy's coordinates and have it check to see if it's within the range of the player. I don't want to resort to using Sprites and use hitTest() since efficiency is an issue. Anyway, the problem lies in the fact that the function below always returns true (even when the player is nowhere near the enemy).

private function quickHitTest(boxLeft:int, boxRight:int, boxTop:int, boxBottom:int, rangeWidth:int, rangeHeight:int):Boolean

return ((boxLeft > (300 - (rangeWidth/2)) && (boxBottom > (450 + (rangeHeight / 2)) || boxTop < (450 - (rangeHeight / 2)))) || (boxRight < (300 + (rangeWidth/2)) && (boxBottom > (450 + (rangeHeight / 2)) || boxTop < (450 - (rangeHeight / 2)))));


I having difficulties finding the source of the problem. All help is appreciated.

• Why don't you use flash.geom.Rectangle ? There are methods containsPoint(Point p):Boolean and intersects(Rectangle r):Boolean - see help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/… – Ivan Kuckir Feb 2 '13 at 19:03
• @IvanKuckir Didn't know they existed (haven't exactly played around with flash.geom.Rectangle). I'll keep them in mind for future reference since I'm working on minimizing operations. – David Feb 2 '13 at 19:06