Phaser API Documentation

  Version: 
collide(object1, [object2], [collideCallback], [processCallback], [callbackContext])

Description:

Performs a collision check and separation between the two physics enabled objects given, which can be single Game Objects, arrays of Game Objects, Physics Groups, arrays of Physics Groups or normal Groups.

If you don't require separation then use Phaser.Physics.Arcade.World#overlap instead.

If two Groups or arrays are passed, each member of one will be tested against each member of the other.

If only one Group is passed (as object1), each member of the Group will be collided against the other members.

If only one Array is passed, the array is iterated and every element in it is tested against the others.

Two callbacks can be provided; they receive the colliding game objects as arguments. If an overlap is detected, the processCallback is called first. It can cancel the collision by returning false. Next the objects are separated and collideCallback is invoked.

Arcade Physics uses the Projection Method of collision resolution and separation. While it's fast and suitable for 'arcade' style games it lacks stability when multiple objects are in close proximity or resting upon each other. The separation that stops two objects penetrating may create a new penetration against a different object. If you require a high level of stability please consider using an alternative physics system, such as Matter.js.

Parameters:

name type arguments description
object1 Phaser.Types.Physics.Arcade.ArcadeColliderType

The first object or array of objects to check.

object2 Phaser.Types.Physics.Arcade.ArcadeColliderType <optional>

The second object or array of objects to check, or undefined.

collideCallback ArcadePhysicsCallback <optional>

An optional callback function that is called if the objects collide.

processCallback ArcadePhysicsCallback <optional>

An optional callback function that lets you perform additional checks against the two objects if they collide. If this is set then collideCallback will only be called if this callback returns true.

callbackContext any <optional>

The context in which to run the callbacks.

Returns:
Description:

true if any overlapping Game Objects were separated, otherwise false.

Type:
  • boolean
Examples:
Since: 3.0.0