Posted By

godstroke on 12/19/10


Tagged

flash game gamedev Flixel GameProgramming


Versions (?)

Check if the FlxObject is inside the given rectangle


 / Published in: ActionScript 3
 

Simple snippet to check is Flixel's flxObjects position according to a rectangle. It will return true if it's inside the rectangle, false if not.

Very basic primitive box collision checking.

  1. private function isInRect(ob:FlxObject,rect:Rectangle):Boolean {
  2. if ((ob.right) >= rect.x
  3. && (ob.left) <= (rect.x + rect.width)
  4. && ob.bottom >= rect.y
  5. && ob.bottom <= rect.y + rect.height // change bottom to top if you allow objects feet should go beyond rectangles bottom.
  6. ) {
  7. return true;
  8. }else {
  9. return false;
  10. }
  11. }

Report this snippet  

You need to login to post a comment.