-
config( [options])
-
Configure ray.
Parameters:
Name |
Type |
Argument |
Description |
options |
object
|
<optional>
|
Ray's congfiguration options. May include:
Properties
Name |
Type |
Argument |
Default |
Description |
origin |
Phaser.Geom.Point
|
Point
|
<optional>
|
{x:0, y:0}
|
Ray's position. |
angle |
number
|
<optional>
|
0
|
Ray's angle in radians. |
angleDeg |
number
|
<optional>
|
0
|
Ray's angle in degrees. |
cone |
number
|
<optional>
|
0
|
Ray's cone angle in radians. |
coneDeg |
number
|
<optional>
|
0
|
Ray's cone angle in degrees. |
range |
number
|
<optional>
|
Phaser.Math.MAX_SAFE_INTEGER
|
Ray's range. |
collisionRange |
number
|
<optional>
|
Phaser.Math.MAX_SAFE_INTEGER
|
Ray's maximum collision range of ray's field of view. |
detectionRange |
number
|
<optional>
|
Phaser.Math.MAX_SAFE_INTEGER
|
Maximum distance between ray's position and tested objects bounding boxes. |
ignoreNotIntersectedRays |
boolean
|
<optional>
|
true
|
If set true, ray returns false when it didn't hit anything. Otherwise returns ray's target position. |
autoSlice |
boolean
|
<optional>
|
false
|
If set true, ray will automatically slice intersections into array of triangles and store it in Ray.slicedIntersections. |
round |
boolean
|
<optional>
|
false
|
If set true, point where ray hit will be rounded. |
enablePhysics |
boolean
|
'arcade'
|
'matter'
|
<optional>
|
false
|
Add to ray physics body. Body will be a circle with radius equal to Ray.collisionRange. If set true, arcade physics body will be added. |
|
- Since:
-
- Source:
-
Returns:
-
Type
-
Raycaster.Ray
-
cast( [options])
-
Cast ray to find closest intersection with tested mapped objects.
Parameters:
Name |
Type |
Argument |
Description |
options |
object
|
<optional>
|
options that may include:
Properties
Name |
Type |
Argument |
Default |
Description |
objects |
Array.<object>
|
<optional>
|
{Raycaster#mappedObjects}
|
Array of game objects to test. If not provided test all mapped game objects. |
target |
Phaser.Geom.Point
|
Point
|
<optional>
|
|
Ray's target point. Used in other casting methods to determine if ray was targeting mapped objects point. |
internal |
boolean
|
<optional>
|
false
|
Flag determining if method is used by other casting method. |
|
- Since:
-
- Source:
-
Returns:
Ray's closest intersection with tested objects. Returns false if no intersection has been found. Additionally contains reference to hit mapped object and segment if available.
-
Type
-
Phaser.Geom.Point
|
boolean
-
castCircle( [options])
-
Cast ray in all directions to find closest intersections with tested mapped objects.
Parameters:
Name |
Type |
Argument |
Description |
options |
object
|
<optional>
|
options that may include:
Properties
Name |
Type |
Argument |
Default |
Description |
objects |
Array.<object>
|
<optional>
|
Raycaster.mappedObjects
|
Array of game objects to test. If not provided test all mapped game objects. |
|
- Since:
-
- Source:
-
Returns:
Array of points of ray's closest intersections with tested objects. Additionally each point contains reference to hit mapped object and it's segment if available.
-
Type
-
Array.<Phaser.Geom.Point>
-
castCone( [options])
-
Cast ray in a cone to find closest intersections with tested mapped objects.
Parameters:
Name |
Type |
Argument |
Description |
options |
object
|
<optional>
|
options that may include:
Properties
Name |
Type |
Argument |
Default |
Description |
objects |
Array.<object>
|
<optional>
|
Raycaster.mappedObjects
|
Array of game objects to test. If not provided test all mapped game objects. |
|
- Since:
-
- Source:
-
Returns:
Array of points of ray's closest intersections with tested objects. Additionally each point contains reference to hit mapped object and it's segment if available.
-
Type
-
Array.<Phaser.Geom.Point>
-
setRay(x, y [, angle] [, range])
-
Set ray's position, direction (angle) and range.
Parameters:
Name |
Type |
Argument |
Default |
Description |
x |
number
|
|
|
X coordinate. |
y |
number
|
|
|
Y coordinate. |
angle |
number
|
<optional>
|
|
Ray's angle in radians. |
range |
number
|
<optional>
|
Phaser.Math.MAX_SAFE_INTEGER
|
Ray's range. |
- Since:
-
- Source:
-
Returns:
-
Type
-
Raycaster.Ray
-
setOrigin(x, y)
-
Set ray's source position.
Parameters:
Name |
Type |
Description |
x |
number
|
X coordinate. |
y |
number
|
Y coordinate. |
- Since:
-
- Source:
-
Returns:
-
Type
-
Raycaster.Ray
-
setAngle( [angle])
-
Set ray's angle (direction) in radians.
Parameters:
Name |
Type |
Argument |
Default |
Description |
angle |
number
|
<optional>
|
0
|
Ray's angle in radians. |
- Since:
-
- Source:
-
Returns:
-
Type
-
Raycaster.Ray
-
setAngleDeg( [angle])
-
Set ray's angle (direction) in degrees.
Parameters:
Name |
Type |
Argument |
Default |
Description |
angle |
number
|
<optional>
|
0
|
Ray's angle in degrees. |
- Since:
-
- Source:
-
Returns:
-
Type
-
Raycaster.Ray
-
setRayRange( [rayRange])
-
Set ray's range.
Parameters:
Name |
Type |
Argument |
Default |
Description |
rayRange |
number
|
<optional>
|
Phaser.Math.MAX_SAFE_INTEGER
|
Ray's range. |
- Since:
-
- Source:
-
Returns:
-
Type
-
Raycaster.Ray
-
setDetectionRange( [detectionRange])
-
Set ray's maximum detection range. Objects outside detection range won't be tested.
Ray tests all objects when set to 0.
Parameters:
Name |
Type |
Argument |
Default |
Description |
detectionRange |
number
|
<optional>
|
0
|
Maximum distance between ray's position and tested objects bounding boxes. |
- Since:
-
- Source:
-
Returns:
-
Type
-
Raycaster.Ray
-
setCollisionRange( [collisionRange])
-
Set ray's field of view maximum collision range. Objects outside collision range won't be tested by
Raycaster.Ray.overlap method.
Determines ray's physics body radius.
Parameters:
Name |
Type |
Argument |
Default |
Description |
collisionRange |
number
|
<optional>
|
Phaser.Math.MAX_SAFE_INTEGER
|
Ray's collision range and physics body radius. |
- Since:
-
- Source:
-
Returns:
-
Type
-
Raycaster.Ray
-
boundsInRange(object [, bounds])
-
Test if object's bounding box is in ray's detection range.
Parameters:
Name |
Type |
Argument |
Default |
Description |
object |
object
|
|
|
Tested object |
bounds |
Phaser.Geom.Rectangle
|
boolean
|
<optional>
|
false
|
Tested object's bounds. If not passed bounds will be generated automatically. |
- Since:
-
- Source:
-
Returns:
Information if object is in ray's detection range.
-
Type
-
boolean
-
setCone( [cone])
-
Set ray's cone angle (width) in radians.
Parameters:
Name |
Type |
Argument |
Default |
Description |
cone |
number
|
<optional>
|
0
|
Ray's cone angle in radians. |
- Since:
-
- Source:
-
Returns:
-
Type
-
Raycaster.Ray
-
setConeDeg( [cone])
-
Set ray's cone angle (width) in degrees.
Parameters:
Name |
Type |
Argument |
Default |
Description |
cone |
number
|
<optional>
|
0
|
Ray's cone angle in degrees. |
- Since:
-
- Source:
-
Returns:
-
Type
-
Raycaster.Ray
-
overlap( [objects])
-
Get game objects overlaping field of view.
Parameters:
Name |
Type |
Argument |
Description |
objects |
object
|
Array.<object>
|
<optional>
|
Game object / array off game objects to test. |
- Since:
-
- Source:
-
Returns:
Array of game objects that overlaps with field of view.
-
Type
-
Array.<object>
-
processOverlap(object1, object2)
-
Process callback for physics collider / overlap.
Parameters:
Name |
Type |
Description |
object1 |
object
|
Game object or matter body passed by collider / overlap or matter CollisionInfo object. |
object2 |
object
|
Game object or matter body passed by collider / overlap. Ignored if matter CollisionInfo object was passed as first argument. |
- Since:
-
- Source:
-
Returns:
Return true if game object is overlapping ray's field of view.
-
Type
-
boolean
-
enablePhysics( [type])
-
Add to ray physics body. Body will be a circle with radius equal to
Ray.collisionRange. Physics body can be added only once.
Parameters:
Name |
Type |
Argument |
Default |
Description |
type |
'arcade'
|
'matter'
|
<optional>
|
'arcade'
|
Physics type |
- Since:
-
- Source:
-
Returns:
-
Type
-
Raycaster.Ray
-
setCollisionCategory(value)
-
Sets the collision category of this ray's Matter Body. This number must be a power of two between 2^0 (= 1) and 2^31.
Two bodies with different collision groups (see #setCollisionGroup) will only collide if their collision
categories are included in their collision masks (see #setCollidesWith).
Parameters:
Name |
Type |
Description |
value |
number
|
Unique category bitfield. |
- Since:
-
- Source:
-
Returns:
-
Type
-
Raycaster.Ray
-
setCollisionCategory(value)
-
Sets the collision group of this ray's Matter Body. If this is zero or two Matter Bodies have different values,
they will collide according to the usual rules (see #setCollisionCategory and #setCollisionGroup).
If two Matter Bodies have the same positive value, they will always collide; if they have the same negative value,
they will never collide.
Parameters:
Name |
Type |
Description |
value |
number
|
Unique group index. |
- Since:
-
- Source:
-
Returns:
-
Type
-
Raycaster.Ray
-
setCollidesWith(categories)
-
Sets the collision mask for this ray's Matter Body. Two Matter Bodies with different collision groups will only
collide if each one includes the other's category in its mask based on a bitwise AND, i.e. `(categoryA & maskB) !== 0`
and `(categoryB & maskA) !== 0` are both true.*
Parameters:
Name |
Type |
Description |
categories |
number
|
Array.<number>
|
A unique category bitfield, or an array of them. |
- Since:
-
- Source:
-
Returns:
-
Type
-
Raycaster.Ray
-
setOnCollide(callback)
-
The callback is sent a `Phaser.Types.Physics.Matter.MatterCollisionData` object.
This does not change the bodies collision category, group or filter. Those must be set in addition
to the callback.
Parameters:
Name |
Type |
Description |
callback |
function
|
The callback to invoke when this body starts colliding with another. |
- Since:
-
- Source:
-
Returns:
-
Type
-
Raycaster.Ray
-
setOnCollideEnd(callback)
-
The callback is sent a `Phaser.Types.Physics.Matter.MatterCollisionData` object.
This does not change the bodies collision category, group or filter. Those must be set in addition
to the callback.
Parameters:
Name |
Type |
Description |
callback |
function
|
The callback to invoke when this body stops colliding with another. |
- Since:
-
- Source:
-
Returns:
-
Type
-
Raycaster.Ray
-
setOnCollideActive(callback)
-
The callback is sent a `Phaser.Types.Physics.Matter.MatterCollisionData` object.
This does not change the bodies collision category, group or filter. Those must be set in addition
to the callback.
Parameters:
Name |
Type |
Description |
callback |
function
|
The callback to invoke for the duration of this body colliding with another. |
- Since:
-
- Source:
-
Returns:
-
Type
-
Raycaster.Ray
-
setOnCollideWith(body, callback)
-
The callback is sent a reference to the other body, along with a `Phaser.Types.Physics.Matter.MatterCollisionData` object.
This does not change the bodies collision category, group or filter. Those must be set in addition
to the callback.
Parameters:
Name |
Type |
Description |
body |
MatterJS.Body
|
Array.<MatterJS.Body>
|
The body, or an array of bodies, to test for collisions with. |
callback |
function
|
The callback to invoke when this body collides with the given body or bodies. |
- Since:
-
- Source:
-
Returns:
-
Type
-
Raycaster.Ray