Namespace: Distance

Phaser.Math. Distance

Methods

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

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.

Since: 3.0.0
Source: src/math/distance/DistanceBetween.js (Line 7)
Returns:

The distance between each point.

Type
number

<static> BetweenPoints(a, b)

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.

Since: 3.22.0
Source: src/math/distance/DistanceBetweenPoints.js (Line 7)
Returns:

The distance between the points.

Type
number

<static> BetweenPointsSquared(a, b)

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.

Since: 3.22.0
Source: src/math/distance/DistanceBetweenPointsSquared.js (Line 7)
Returns:

The squared distance between the points.

Type
number

<static> Chebyshev(x1, y1, x2, y2)

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.

Since: 3.22.0
Source: src/math/distance/DistanceChebyshev.js (Line 7)
Returns:

The distance between each point.

Type
number

<static> Power(x1, y1, x2, y2, pow)

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.

Since: 3.0.0
Source: src/math/distance/DistancePower.js (Line 7)
Returns:

The distance between each point.

Type
number

<static> Snake(x1, y1, x2, y2)

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.

Since: 3.22.0
Source: src/math/distance/DistanceSnake.js (Line 7)
Returns:

The distance between each point.

Type
number

<static> Squared(x1, y1, x2, y2)

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.

Since: 3.0.0
Source: src/math/distance/DistanceSquared.js (Line 7)
Returns:

The distance between each point, squared.

Type
number