Check if the FlxObject is inside the given rectangle


/ Published in: ActionScript 3
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.