Phaser API Documentation

  Version: 
Filter
Namespace: Distance
Phaser.Math.Distance
Source: src/math/distance/index.js (Line 7)

Methods

<static> Between(x1, y1, x2, y2)
Focus
Focus

Description:

Calculate the distance between two sets of coordinates (points).

Parameters:

name type description
x1 number

The x coordinate of the first point.

y1 number

The y coordinate of the first point.

x2 number

The x coordinate of the second point.

y2 number

The y coordinate of the second point.

Returns:
Description:

The distance between each point.

Type:
  • number
Since: 3.0.0
Focus
Focus
<static> BetweenPoints(a, b)
Focus
Focus

Description:

Calculate the distance between two points.

Parameters:

name type description
a Phaser.Types.Math.Vector2Like

The first point.

b Phaser.Types.Math.Vector2Like

The second point.

Returns:
Description:

The distance between the points.

Type:
  • number
Since: 3.22.0
Focus
Focus
<static> BetweenPointsSquared(a, b)
Focus
Focus

Description:

Calculate the squared distance between two points.

Parameters:

name type description
a Phaser.Types.Math.Vector2Like

The first point.

b Phaser.Types.Math.Vector2Like

The second point.

Returns:
Description:

The squared distance between the points.

Type:
  • number
Focus
Focus
<static> Chebyshev(x1, y1, x2, y2)
Focus
Focus

Description:

Calculate the Chebyshev distance between two sets of coordinates (points).

Chebyshev distance (or chessboard distance) is the maximum of the horizontal and vertical distances. It's the effective distance when movement can be horizontal, vertical, or diagonal.

Parameters:

name type description
x1 number

The x coordinate of the first point.

y1 number

The y coordinate of the first point.

x2 number

The x coordinate of the second point.

y2 number

The y coordinate of the second point.

Returns:
Description:

The distance between each point.

Type:
  • number
Since: 3.22.0
Focus
Focus
<static> Power(x1, y1, x2, y2, pow)
Focus
Focus

Description:

Calculate the distance between two sets of coordinates (points) to the power of pow.

Parameters:

name type description
x1 number

The x coordinate of the first point.

y1 number

The y coordinate of the first point.

x2 number

The x coordinate of the second point.

y2 number

The y coordinate of the second point.

pow number

The exponent.

Returns:
Description:

The distance between each point.

Type:
  • number
Since: 3.0.0
Focus
Focus
<static> Snake(x1, y1, x2, y2)
Focus
Focus

Description:

Calculate the snake distance between two sets of coordinates (points).

Snake distance (rectilinear distance, Manhattan distance) is the sum of the horizontal and vertical distances. It's the effective distance when movement is allowed only horizontally or vertically (but not both).

Parameters:

name type description
x1 number

The x coordinate of the first point.

y1 number

The y coordinate of the first point.

x2 number

The x coordinate of the second point.

y2 number

The y coordinate of the second point.

Returns:
Description:

The distance between each point.

Type:
  • number
Since: 3.22.0
Focus
Focus
<static> Squared(x1, y1, x2, y2)
Focus
Focus

Description:

Calculate the distance between two sets of coordinates (points), squared.

Parameters:

name type description
x1 number

The x coordinate of the first point.

y1 number

The y coordinate of the first point.

x2 number

The x coordinate of the second point.

y2 number

The y coordinate of the second point.

Returns:
Description:

The distance between each point, squared.

Type:
  • number
Since: 3.0.0
Focus
Focus