Reputation:
I have two shapes, both circles, and they are moving on the stage. They are just bouncing off the boundaries of the stage when they reach it. What they never do is collide, which is something I would like to add some logic for. As close as I have gotten is
shape1.intersects(shape2.getPosition());
but that doesn't really come close to what I want to achieve, which would be perimeter collision detection, not just if one point is in another shape.
Upvotes: 2
Views: 772
Reputation: 11755
Try simple bounding box collision detection:
function doObjectsCollide(a, b) { // a and b are your objects
return !(
((a.getY() + a.getHeight()) < (b.getY())) ||
(a.getY() > (b.y + b.getHeight())) ||
((a.getX() + a.getWidth()) < b.getX()) ||
(a.getX() > (b.getX() + b.getWidth()))
);
}
Upvotes: 1