You’re reading the docs for Phaser v4.0.0. The latest is Phaser v4.1.0.

Phaser.Math.Distance

Scope: static

Source: src/math/distance/index.js#L7

Static functions

Between

staticBetween(x1, y1, x2, y2)

Description:

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

Parameters:

nametypeoptionaldescription
x1numberNoThe x coordinate of the first point.
y1numberNoThe y coordinate of the first point.
x2numberNoThe x coordinate of the second point.
y2numberNoThe y coordinate of the second point.

Returns: number - The distance between each point.

Source: src/math/distance/DistanceBetween.js#L7
Since: 3.0.0


BetweenPoints

staticBetweenPoints(a, b)

Description:

Calculate the distance between two points.

Parameters:

nametypeoptionaldescription
aPhaser.Types.Math.Vector2LikeNoThe first point.
bPhaser.Types.Math.Vector2LikeNoThe second point.

Returns: number - The distance between the points.

Source: src/math/distance/DistanceBetweenPoints.js#L7
Since: 3.22.0


BetweenPointsSquared

staticBetweenPointsSquared(a, b)

Description:

Calculate the squared distance between two points.

Parameters:

nametypeoptionaldescription
aPhaser.Types.Math.Vector2LikeNoThe first point.
bPhaser.Types.Math.Vector2LikeNoThe second point.

Returns: number - The squared distance between the points.

Source: src/math/distance/DistanceBetweenPointsSquared.js#L7
Since: 3.22.0


Chebyshev

staticChebyshev(x1, y1, x2, y2)

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:

nametypeoptionaldescription
x1numberNoThe x coordinate of the first point.
y1numberNoThe y coordinate of the first point.
x2numberNoThe x coordinate of the second point.
y2numberNoThe y coordinate of the second point.

Returns: number - The distance between each point.

Source: src/math/distance/DistanceChebyshev.js#L7
Since: 3.22.0


Power

staticPower(x1, y1, x2, y2, [pow])

Description:

Calculate the distance between two sets of coordinates using the generalized power formula: sqrt((x2 - x1)^pow + (y2 - y1)^pow). When pow is 2 this is equivalent to standard Euclidean distance. Increasing pow emphasizes larger axis differences.

Parameters:

nametypeoptionaldefaultdescription
x1numberNoThe x coordinate of the first point.
y1numberNoThe y coordinate of the first point.
x2numberNoThe x coordinate of the second point.
y2numberNoThe y coordinate of the second point.
pownumberYes2The exponent applied to each axis difference. Defaults to 2, which gives standard Euclidean distance.

Returns: number - The distance between the two points.

Source: src/math/distance/DistancePower.js#L7
Since: 3.0.0


Snake

staticSnake(x1, y1, x2, y2)

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:

nametypeoptionaldescription
x1numberNoThe x coordinate of the first point.
y1numberNoThe y coordinate of the first point.
x2numberNoThe x coordinate of the second point.
y2numberNoThe y coordinate of the second point.

Returns: number - The distance between each point.

Source: src/math/distance/DistanceSnake.js#L7
Since: 3.22.0


Squared

staticSquared(x1, y1, x2, y2)

Description:

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

Parameters:

nametypeoptionaldescription
x1numberNoThe x coordinate of the first point.
y1numberNoThe y coordinate of the first point.
x2numberNoThe x coordinate of the second point.
y2numberNoThe y coordinate of the second point.

Returns: number - The distance between each point, squared.

Source: src/math/distance/DistanceSquared.js#L7
Since: 3.0.0