Physics.Arcade#distanceToXY()

distanceToXY(displayObject, x, y, world) → {number}

Find the distance between a display object (like a Sprite) and the given x/y coordinates.
The calculation is made from the display objects x/y coordinate. This may be the top-left if its anchor hasn't been changed.
If you need to calculate from the center of a display object instead use the method distanceBetweenCenters()

The optional world argument allows you to return the result based on the Game Objects world property,
instead of its x and y values. This is useful of the object has been nested inside an offset Group,
or parent Game Object.

Parameters
Name Type Argument Default Description
displayObject any

The Display Object to test from.

x number

The x coordinate to move towards.

y number

The y coordinate to move towards.

world boolean <optional>
false

Calculate the distance using World coordinates (true), or Object coordinates (false, the default)

Returns
number -

The distance between the object and the x/y coordinates.

Source code: physics/arcade/World.js (Line 1942)
doc_phaser
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.