Physics.P2.BodyDebug#getClosestTo()

getClosestTo(object, callback, callbackContext) → {any}

Get the closest child to given Object, with optional callback to filter children.

This can be a Sprite, Group, Image or any object with public x and y properties.

'close' is determined by the distance from the objects x and y properties compared to the childs x and y properties.

You can use the optional callback argument to apply your own filter to the distance checks.
If the child is closer then the previous child, it will be sent to callback as the first argument,
with the distance as the second. The callback should return true if it passes your
filtering criteria, otherwise it should return false.

Parameters
Name Type Argument Description
object any

The object used to determine the distance. This can be a Sprite, Group, Image or any object with public x and y properties.

callback function <optional>

The function that each child will be evaluated against. Each child of the group will be passed to it as its first parameter, with the distance as the second. It should return true if the child passes the matching criteria.

callbackContext object <optional>

The context in which the function should be called (usually 'this').

Returns
any -

The child closest to given object, or null if no child was found.

Inherited From
Source code: core/Group.js (Line 2238)
doc_phaser
2017-02-14 11:03:26
Comments
Leave a Comment

Please login to continue.