Phaser API Documentation

  Version: 
overlap(target, [bodies], [overlapCallback], [processCallback], [callbackContext])

Description:

Checks to see if the target body, or an array of target bodies, intersects with any of the given bodies.

If intersection occurs this method will return true and, if provided, invoke the callbacks.

If no bodies are provided for the second parameter the target will check again all bodies in the Matter World.

Note that bodies can only overlap if they are in non-colliding collision groups or categories.

If you provide a processCallback then the two bodies that overlap are sent to it. This callback must return a boolean and is used to allow you to perform additional processing tests before a final outcome is decided. If it returns true then the bodies are finally passed to the overlapCallback, if set.

If you provide an overlapCallback then the matching pairs of overlapping bodies will be sent to it.

Both callbacks have the following signature: function (bodyA, bodyB, collisionInfo) where bodyA is always the target body. The collisionInfo object contains additional data, such as the angle and depth of penetration.

Parameters:

name type arguments description
target Phaser.Types.Physics.Matter.MatterBody | Array.<Phaser.Types.Physics.Matter.MatterBody>

The target body, or array of target bodies, to check.

bodies Array.<Phaser.Types.Physics.Matter.MatterBody> <optional>

The second body, or array of bodies, to check. If falsey it will check against all bodies in the world.

overlapCallback ArcadePhysicsCallback <optional>

An optional callback function that is called if the bodies overlap.

processCallback ArcadePhysicsCallback <optional>

An optional callback function that lets you perform additional checks against the two bodies if they overlap. If this is set then overlapCallback will only be invoked if this callback returns true.

callbackContext * <optional>

The context, or scope, in which to run the callbacks.

Returns:
Description:

true if the target body intersects with any of the bodies given, otherwise false.

Type:
  • boolean
Since: 3.22.0