Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Why don't you use flash.geom.Rectangle ? There are methods containsPoint(Point p):Boolean and intersects(Rectangle r):Boolean - see… – 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
up vote 1 down vote accepted

Why make it so complicated? If you have the coordinates of both the player and the enemy you can just calculate the distance and see if it falls within the range. Or am i misunderstanding something?

share|improve this answer
Damn. Not sure how I managed to overlook that. – David Feb 2 '13 at 16:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.