collide(object1, object2, collideCallback, processCallback, callbackContext) → {boolean}
Checks for collision between two game objects. You can perform Sprite vs. Sprite, Sprite vs. Group, Group vs. Group, Sprite vs. Tilemap Layer or Group vs. Tilemap Layer collisions.
The second parameter can be an array of objects, of differing types.
The objects are also automatically separated. If you don't require separation then use ArcadePhysics.overlap instead.
An optional processCallback can be provided. If given this function will be called when two sprites are found to be colliding. It is called before any separation takes place,
giving you the chance to perform additional checks. If the function returns true then the collision and separation is carried out. If it returns false it is skipped.
The collideCallback is an optional function that is only called if two sprites collide. If a processCallback has been set then it needs to return true for collideCallback to be called.
Parameters
Name | Type | Argument | Default | Description |
---|---|---|---|---|
object1 | Phaser.Sprite | Phaser.Group | Phaser.Particles.Emitter | Phaser.TilemapLayer | The first object to check. Can be an instance of Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter, or Phaser.TilemapLayer. | ||
object2 | Phaser.Sprite | Phaser.Group | Phaser.Particles.Emitter | Phaser.TilemapLayer | array | The second object or array of objects to check. Can be Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter or Phaser.TilemapLayer. | ||
collideCallback | function | <optional> | null | An optional callback function that is called if the objects collide. The two objects will be passed to this function in the same order in which you specified them. |
processCallback | function | <optional> | null | A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then collision will only happen if processCallback returns true. The two objects will be passed to this function in the same order in which you specified them. |
callbackContext | object | <optional> | The context in which to run the callbacks. |
Returns
True if a collision occured otherwise false.
- Source code: physics/ninja/World.js (Line 330)
Please login to continue.