FlxG.overlap()
not only works between 2 FlxObject
s, but you can also pass in a FlxGroup
to either arg.
FlxG.overlap()
will still return whether it detected any overlap between the groups, but it is usually wise to use a notifyCallback
to handle each specific overlap.
Performance
FlxG.overlap()
uses quadtrees on groups to greatly reduce the number of comparisons between objects, meaning that a single call with 2 groups can perform immensely better than checking whether each pair of objects overlaps, individually.
function handleCollision(objA:FlxObject, objB:FlxObject)
{
trace('overlap between a: $objA and b:$objB');
}
// check if any objects in groupA overlap any objects in groupB
FlxG.overlap(groupA, groupB, handleCollision);
// check if the player overlaps anything in groupB
FlxG.overlap(player, groupB, handleCollision);
// Check if any objects in groupA overlap each other
FlxG.overlap(groupA, groupA, handleCollision);