Phaser API Documentation

  Version: 
closest(source, [targets])

Description:

Finds the Body or Game Object closest to a source point or object.

If a targets argument is passed, this method finds the closest of those. The targets can be Arcade Physics Game Objects, Dynamic Bodies, or Static Bodies.

If no targets argument is passed, this method finds the closest Dynamic Body.

If two or more targets are the exact same distance from the source point, only the first target is returned.

Parameters:

name type arguments description
source any

Any object with public x and y properties, such as a Game Object or Geometry object.

targets Array.<Phaser.Physics.Arcade.Body> | Array.<Phaser.Physics.Arcade.StaticBody> | Array.<Phaser.GameObjects.GameObject> <optional>

The targets.

Returns:
Description:

The target closest to the given source point.

Since: 3.0.0