Class: Arcade

Phaser.Physics. Arcade

new Arcade(game)

The Arcade Physics world. Contains Arcade Physics related collision, overlap and motion methods.

Parameters:
Name Type Description
game Phaser.Game

reference to the current game instance.

Source:
src/physics/arcade/World.js line 14

Classes

Body
TilemapCollision

Members

<static, constant> BOTTOM_TOP : number

A constant used for the sortDirection value. Use this if your game world is narrow but tall and scrolls from the bottom to the top (i.e. Commando or a vertically scrolling shoot-em-up)

Type:
  • number
Source:
src/physics/arcade/World.js line 130

<static, constant> LEFT_RIGHT : number

A constant used for the sortDirection value. Use this if your game world is wide but short and scrolls from the left to the right (i.e. Mario)

Type:
  • number
Source:
src/physics/arcade/World.js line 106

<static, constant> RIGHT_LEFT : number

A constant used for the sortDirection value. Use this if your game world is wide but short and scrolls from the right to the left (i.e. Mario backwards)

Type:
  • number
Source:
src/physics/arcade/World.js line 114

<static, constant> SORT_NONE : number

A constant used for the sortDirection value. Use this if you don't wish to perform any pre-collision sorting at all, or will manually sort your Groups.

Type:
  • number
Source:
src/physics/arcade/World.js line 98

<static, constant> TOP_BOTTOM : number

A constant used for the sortDirection value. Use this if your game world is narrow but tall and scrolls from the top to the bottom (i.e. Dig Dug)

Type:
  • number
Source:
src/physics/arcade/World.js line 122

bounds : Phaser.Rectangle

The bounds inside of which the physics world exists. Defaults to match the world bounds.

Type:
Source:
src/physics/arcade/World.js line 29

checkCollision : object

Which edges of the World bounds Bodies can collide against when collideWorldBounds is true. For example checkCollision.down = false means Bodies cannot collide with the World.bounds.bottom. An object containing allowed collision flags (up, down, left, right).

Type:
  • object
Source:
src/physics/arcade/World.js line 36

forceX : boolean

If true World.separate will always separate on the X axis before Y. Otherwise it will check gravity totals first.

Type:
  • boolean
Source:
src/physics/arcade/World.js line 57

game : Phaser.Game

Local reference to game.

Type:
Source:
src/physics/arcade/World.js line 19

gravity : Phaser.Point

The World gravity setting. Defaults to x: 0, y: 0, or no gravity.

Type:
Source:
src/physics/arcade/World.js line 24

isPaused : boolean

If true the Body.preUpdate method will be skipped, halting all motion for all bodies. Note that other methods such as collide will still work, so be careful not to call them on paused bodies.

Type:
  • boolean
Source:
src/physics/arcade/World.js line 73

maxLevels : number

Used by the QuadTree to set the maximum number of iteration levels.

Type:
  • number
Source:
src/physics/arcade/World.js line 46

maxObjects : number

Used by the QuadTree to set the maximum number of objects per quad.

Type:
  • number
Source:
src/physics/arcade/World.js line 41

OVERLAP_BIAS : number

A value added to the delta values during collision checks. Increase it to prevent sprite tunneling.

Type:
  • number
Default Value:
  • 4
Source:
src/physics/arcade/World.js line 52

quadTree : Phaser.QuadTree

The world QuadTree.

Type:
Source:
src/physics/arcade/World.js line 78

skipQuadTree : boolean

If true the QuadTree will not be used for any collision. QuadTrees are great if objects are well spread out in your game, otherwise they are a performance hit. If you enable this you can disable on a per body basis via Body.skipQuadTree.

Type:
  • boolean
Source:
src/physics/arcade/World.js line 68

sortDirection : number

Used when colliding a Sprite vs. a Group, or a Group vs. a Group, this defines the direction the sort is based on. Default is Phaser.Physics.Arcade.LEFT_RIGHT.

Type:
  • number
Source:
src/physics/arcade/World.js line 63

Methods

accelerateToObject(displayObject, destination [, speed] [, xSpeedMax] [, ySpeedMax])

Sets the acceleration.x/y property on the display object so it will move towards the target at the given speed (in pixels per second sq.) You must give a maximum speed value, beyond which the display object won't go any faster. Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course. Note: The display object doesn't stop moving once it reaches the destination coordinates.

Parameters:
Name Type Argument Default Description
displayObject any

The display object to move.

destination any

The display object to move towards. Can be any object but must have visible x/y properties.

speed number <optional>
60

The speed it will accelerate in pixels per second.

xSpeedMax number <optional>
500

The maximum x velocity the display object can reach.

ySpeedMax number <optional>
500

The maximum y velocity the display object can reach.

Source:
src/physics/arcade/World.js line 1828
Returns:

The angle (in radians) that the object should be visually set to in order to match its new trajectory.

Type
number

accelerateToPointer(displayObject [, pointer] [, speed] [, xSpeedMax] [, ySpeedMax])

Sets the acceleration.x/y property on the display object so it will move towards the target at the given speed (in pixels per second sq.) You must give a maximum speed value, beyond which the display object won't go any faster. Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course. Note: The display object doesn't stop moving once it reaches the destination coordinates.

Parameters:
Name Type Argument Default Description
displayObject any

The display object to move.

pointer Phaser.Pointer <optional>

The pointer to move towards. Defaults to Phaser.Input.activePointer.

speed number <optional>
60

The speed it will accelerate in pixels per second.

xSpeedMax number <optional>
500

The maximum x velocity the display object can reach.

ySpeedMax number <optional>
500

The maximum y velocity the display object can reach.

Source:
src/physics/arcade/World.js line 1856
Returns:

The angle (in radians) that the object should be visually set to in order to match its new trajectory.

Type
number

accelerateToXY(displayObject, x, y [, speed] [, xSpeedMax] [, ySpeedMax])

Sets the acceleration.x/y property on the display object so it will move towards the x/y coordinates at the given speed (in pixels per second sq.) You must give a maximum speed value, beyond which the display object won't go any faster. Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course. Note: The display object doesn't stop moving once it reaches the destination coordinates.

Parameters:
Name Type Argument Default Description
displayObject any

The display object to move.

x number

The x coordinate to accelerate towards.

y number

The y coordinate to accelerate towards.

speed number <optional>
60

The speed it will accelerate in pixels per second.

xSpeedMax number <optional>
500

The maximum x velocity the display object can reach.

ySpeedMax number <optional>
500

The maximum y velocity the display object can reach.

Source:
src/physics/arcade/World.js line 1885
Returns:

The angle (in radians) that the object should be visually set to in order to match its new trajectory.

Type
number

accelerationFromRotation(rotation [, speed] [, point])

Given the rotation (in radians) and speed calculate the acceleration and return it as a Point object, or set it to the given point object. One way to use this is: accelerationFromRotation(rotation, 200, sprite.acceleration) which will set the values directly to the sprites acceleration and not create a new Point object.

Parameters:
Name Type Argument Default Description
rotation number

The angle in radians.

speed number <optional>
60

The speed it will move, in pixels per second sq.

point Phaser.Point | object <optional>

The Point object in which the x and y properties will be set to the calculated acceleration.

Source:
src/physics/arcade/World.js line 1810
Returns:
  • A Point where point.x contains the acceleration x value and point.y contains the acceleration y value.
Type
Phaser.Point

angleBetween(source, target [, world])

Find the angle in radians between two display objects (like Sprites).

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
source any

The Display Object to test from.

target any

The Display Object to test to.

world boolean <optional>
false

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

Source:
src/physics/arcade/World.js line 2072
Returns:

The angle in radians between the source and target display objects.

Type
number

angleBetweenCenters(source, target)

Find the angle in radians between centers of two display objects (like Sprites).

Parameters:
Name Type Description
source any

The Display Object to test from.

target any

The Display Object to test to.

Source:
src/physics/arcade/World.js line 2099
Returns:

The angle in radians between the source and target display objects.

Type
number

angleToPointer(displayObject [, pointer] [, world])

Find the angle in radians between a display object (like a Sprite) and a Pointer, taking their x/y and center into account.

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.

pointer Phaser.Pointer <optional>

The Phaser.Pointer to test to. If none is given then Input.activePointer is used.

world boolean <optional>
false

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

Source:
src/physics/arcade/World.js line 2143
Returns:

The angle in radians between displayObject.x/y to Pointer.x/y

Type
number

angleToXY(displayObject, x, y [, world])

Find the angle in radians between a display object (like a Sprite) and the given x/y coordinate.

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 get the angle to.

y number

The y coordinate to get the angle to.

world boolean <optional>
false

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

Source:
src/physics/arcade/World.js line 2115
Returns:

The angle in radians between displayObject.x/y to Pointer.x/y

Type
number

circleBodyIntersects(circle, body)

Checks to see if a circular Body intersects with a Rectangular Body.

Parameters:
Name Type Description
circle Phaser.Physics.Arcade.Body

The Body with isCircle set.

body Phaser.Physics.Arcade.Body

The Body with isCircle not set (i.e. uses Rectangle shape)

Source:
src/physics/arcade/World.js line 1137
Returns:

Returns true if the bodies intersect, otherwise false.

Type
boolean

closest(source, targets [, world] [, useCenter])

From a set of points or display objects, find the one closest to a source point or object.

Parameters:
Name Type Argument Default Description
source any

The Point or Display Object distances will be measured from.

targets Array.<any>

The Points or Display Objects whose distances to the source will be compared.

world boolean <optional>
false

Calculate the distance using World coordinates (true), or Object coordinates (false, the default). If useCenter is true, this value is ignored.

useCenter boolean <optional>
false

Calculate the distance using the Phaser.Sprite#centerX and Phaser.Sprite#centerY coordinates. If true, this value overrides the world argument.

Source:
src/physics/arcade/World.js line 2012
Returns:
  • The first target closest to the origin.
Type
any

collide(object1, object2 [, collideCallback] [, processCallback] [, callbackContext])

Checks for collision between two game objects and separates them if colliding (details). If you don't require separation then use overlap instead.

You can perform Sprite vs. Sprite, Sprite vs. Group, Group vs. Group, Sprite vs. Tilemap Layer or Group vs. Tilemap Layer collisions. Both the object1 and object2 can be arrays of objects, of differing types.

If two Groups or arrays are passed, each member of one will be tested against each member of the other.

If one Group only is passed (as object1), each member of the Group will be collided against the other members.

If either object is null the collision test will fail.

Bodies with enable = false and Sprites with exists = false are skipped (ignored).

An optional processCallback can be provided. If given this function will be called when two sprites are found to be colliding. It is called before any separation takes place, giving you the chance to perform additional checks. If the function returns true then the collision and separation is carried out. If it returns false it is skipped.

The collideCallback is an optional function that is only called if two sprites collide. If a processCallback has been set then it needs to return true for collideCallback to be called.

This function is not recursive, and will not test against children of objects passed (i.e. Groups or Tilemaps within other Groups).

Examples
collide(group);
collide(group, undefined); // equivalent

collide(sprite1, sprite2);

collide(sprite, group);

collide(group1, group2);

collide([sprite1, sprite2], [sprite3, sprite4]); // 1 vs. 3, 1 vs. 4, 2 vs. 3, 2 vs. 4
Tilemaps

Tiles marked via Phaser.Tilemap#setCollision (and similar methods) are "solid". If a Sprite collides with one of these tiles, the two are separated by moving the Sprite outside the tile's edges. Enable Phaser.TilemapLayer#debug to see the colliding edges of the Tilemap.

Tiles with a callback attached via Phaser.Tilemap#setTileIndexCallback or Phaser.Tilemap#setTileLocationCallback invoke the callback if a Sprite collides with them. If a tile has a callback attached via both methods, only the location callback is invoked. The colliding Sprite is separated from the tile only if the callback returns true.

Parameters:
Name Type Argument Default Description
object1 Phaser.Sprite | Phaser.Group | Phaser.Particles.Emitter | Phaser.TilemapLayer | array

The first object or array of objects to check. Can be Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter, or Phaser.TilemapLayer.

object2 Phaser.Sprite | Phaser.Group | Phaser.Particles.Emitter | Phaser.TilemapLayer | array

The second object or array of objects to check. Can be Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter or Phaser.TilemapLayer.

collideCallback function <optional>
null

An optional callback function that is called if the objects collide. The two objects will be passed to this function in the same order in which you specified them, unless you are colliding Group vs. Sprite, in which case Sprite will always be the first parameter.

processCallback function <optional>
null

A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then collision will only happen if processCallback returns true. The two objects will be passed to this function in the same order in which you specified them, unless you are colliding Group vs. Sprite, in which case Sprite will always be the first parameter.

callbackContext object <optional>

The context in which to run the callbacks.

Source:
src/physics/arcade/World.js line 353
Returns:

True if a collision occurred otherwise false.

Type
boolean

computeVelocity(axis, body, velocity, acceleration, drag [, max])

A tween-like function that takes a starting velocity and some other factors and returns an altered velocity. Based on a function in Flixel by @ADAMATOMIC

Parameters:
Name Type Argument Default Description
axis number

0 for nothing, 1 for horizontal, 2 for vertical.

body Phaser.Physics.Arcade.Body

The Body object to be updated.

velocity number

Any component of velocity (e.g. 20).

acceleration number

Rate at which the velocity is changing.

drag number

Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set.

max number <optional>
10000

An absolute value cap for the velocity.

Source:
src/physics/arcade/World.js line 253
Returns:

The altered Velocity value.

Type
number

distanceBetween(source, target [, world] [, useCenter])

Find the distance between two display objects (like Sprites).

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.

If you have nested objects and need to calculate the distance between their centers in World coordinates, set their anchors to (0.5, 0.5) and use the world argument.

If objects aren't nested or they share a parent's offset, you can calculate the distance between their centers with the useCenter argument, regardless of their anchor values.

Parameters:
Name Type Argument Default Description
source any

The Display Object to test from.

target any

The Display Object to test to.

world boolean <optional>
false

Calculate the distance using World coordinates (true), or Object coordinates (false, the default). If useCenter is true, this value is ignored.

useCenter boolean <optional>
false

Calculate the distance using the Phaser.Sprite#centerX and Phaser.Sprite#centerY coordinates. If true, this value overrides the world argument.

Source:
src/physics/arcade/World.js line 1914
Returns:

The distance between the source and target objects.

Type
number

distanceToPointer(displayObject [, pointer] [, world])

Find the distance between a display object (like a Sprite) and a Pointer. If no Pointer is given the Input.activePointer is used. 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 distanceBetween with the useCenter argument.

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.

pointer Phaser.Pointer <optional>

The Phaser.Pointer to test to. If none is given then Input.activePointer is used.

world boolean <optional>
false

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

Source:
src/physics/arcade/World.js line 1986
Returns:

The distance between the object and the Pointer.

Type
number

distanceToXY(displayObject, x, y [, world])

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 distanceBetween with the useCenter argument.

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)

Source:
src/physics/arcade/World.js line 1960
Returns:

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

Type
number

enable(object [, children])

This will create an Arcade Physics body on the given game object or array of game objects. A game object can only have 1 physics body active at any one time, and it can't be changed until the object is destroyed.

Parameters:
Name Type Argument Default Description
object object | array | Phaser.Group

The game object to create the physics body on. Can also be an array or Group of objects, a body will be created on every child that has a body property.

children boolean <optional>
true

Should a body be created on all children of this object? If true it will recurse down the display list as far as it can go.

Source:
src/physics/arcade/World.js line 158

enableBody(object)

Creates an Arcade Physics body on the given game object.

A game object can only have 1 physics body active at any one time, and it can't be changed until the body is nulled.

When you add an Arcade Physics body to an object it will automatically add the object into its parent Groups hash array.

Parameters:
Name Type Description
object object

The game object to create the physics body on. A body will only be created if this object has a null body property.

Source:
src/physics/arcade/World.js line 211

farthest(source, targets [, world] [, useCenter])

From a set of points or display objects, find the one farthest from a source point or object.

Parameters:
Name Type Argument Default Description
source any

The Point or Display Object distances will be measured from.

targets Array.<any>

The Points or Display Objects whose distances to the source will be compared.

world boolean <optional>
false

Calculate the distance using World coordinates (true), or Object coordinates (false, the default). If useCenter is true, this value is ignored.

useCenter boolean <optional>
false

Calculate the distance using the Phaser.Sprite#centerX and Phaser.Sprite#centerY coordinates. If true, this value overrides the world argument.

Source:
src/physics/arcade/World.js line 2042
Returns:
  • The target closest to the origin.
Type
any

getObjectsAtLocation(x, y, group [, callback] [, callbackContext] [, callbackArg])

Given a Group and a location this will check to see which Group children overlap with the coordinates. Each child will be sent to the given callback for further processing. Note that the children are not checked for depth order, but simply if they overlap the coordinate or not.

Parameters:
Name Type Argument Description
x number

The x coordinate to check.

y number

The y coordinate to check.

group Phaser.Group

The Group to check.

callback function <optional>

A callback function that is called if the object overlaps the coordinates. The callback will be sent two parameters: the callbackArg and the Object that overlapped the location.

callbackContext object <optional>

The context in which to run the callback.

callbackArg object <optional>

An argument to pass to the callback.

Source:
src/physics/arcade/World.js line 1631
Returns:

An array of the Sprites from the Group that overlapped the coordinates.

Type
Array.<PIXI.DisplayObject>

getObjectsUnderPointer(pointer, group [, callback] [, callbackContext])

Given a Group and a Pointer this will check to see which Group children overlap with the Pointer coordinates. Each child will be sent to the given callback for further processing. Note that the children are not checked for depth order, but simply if they overlap the Pointer or not.

Parameters:
Name Type Argument Description
pointer Phaser.Pointer

The Pointer to check.

group Phaser.Group

The Group to check.

callback function <optional>

A callback function that is called if the object overlaps with the Pointer. The callback will be sent two parameters: the Pointer and the Object that overlapped with it.

callbackContext object <optional>

The context in which to run the callback.

Source:
src/physics/arcade/World.js line 1609
Returns:

An array of the Sprites from the Group that overlapped the Pointer coordinates.

Type
Array.<PIXI.DisplayObject>

getOverlapX(body1, body2, overlapOnly)

Calculates the horizontal overlap between two Bodies and sets their properties accordingly, including: touching.left, touching.right and overlapX.

Parameters:
Name Type Description
body1 Phaser.Physics.Arcade.Body

The first Body to separate.

body2 Phaser.Physics.Arcade.Body

The second Body to separate.

overlapOnly boolean

Is this an overlap only check, or part of separation?

Source:
src/physics/arcade/World.js line 1345
Returns:

Returns the amount of horizontal overlap between the two bodies.

Type
float

getOverlapY(body1, body2, overlapOnly)

Calculates the vertical overlap between two Bodies and sets their properties accordingly, including: touching.up, touching.down and overlapY.

Parameters:
Name Type Description
body1 Phaser.Physics.Arcade.Body

The first Body to separate.

body2 Phaser.Physics.Arcade.Body

The second Body to separate.

overlapOnly boolean

Is this an overlap only check, or part of separation?

Source:
src/physics/arcade/World.js line 1408
Returns:

Returns the amount of vertical overlap between the two bodies.

Type
float

intersects(body1, body2)

Check for intersection against two bodies.

Parameters:
Name Type Description
body1 Phaser.Physics.Arcade.Body

The first Body object to check.

body2 Phaser.Physics.Arcade.Body

The second Body object to check.

Source:
src/physics/arcade/World.js line 1076
Returns:

True if they intersect, otherwise false.

Type
boolean

moveToObject(displayObject, destination [, speed] [, maxTime])

Move the given display object towards the destination object at a steady velocity. If you specify a maxTime then it will adjust the speed (overwriting what you set) so it arrives at the destination in that number of seconds. Timings are approximate due to the way browser timers work. Allow for a variance of +- 50ms. Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course. Note: The display object doesn't stop moving once it reaches the destination coordinates. Note: Doesn't take into account acceleration, maxVelocity or drag (if you've set drag or acceleration too high this object may not move at all)

Parameters:
Name Type Argument Default Description
displayObject any

The display object to move.

destination any

The display object to move towards. Can be any object but must have visible x/y properties.

speed number <optional>
60

The speed it will move, in pixels per second (default is 60 pixels/sec)

maxTime number <optional>
0

Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the object will arrive at destination in the given number of ms.

Source:
src/physics/arcade/World.js line 1674
Returns:

The angle (in radians) that the object should be visually set to in order to match its new velocity.

Type
number

moveToPointer(displayObject [, speed] [, pointer] [, maxTime])

Move the given display object towards the pointer at a steady velocity. If no pointer is given it will use Phaser.Input.activePointer. If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds. Timings are approximate due to the way browser timers work. Allow for a variance of +- 50ms. Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course. Note: The display object doesn't stop moving once it reaches the destination coordinates.

Parameters:
Name Type Argument Default Description
displayObject any

The display object to move.

speed number <optional>
60

The speed it will move, in pixels per second (default is 60 pixels/sec)

pointer Phaser.Pointer <optional>

The pointer to move towards. Defaults to Phaser.Input.activePointer.

maxTime number <optional>
0

Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the object will arrive at destination in the given number of ms.

Source:
src/physics/arcade/World.js line 1707
Returns:

The angle (in radians) that the object should be visually set to in order to match its new velocity.

Type
number

moveToXY(displayObject, x, y [, speed] [, maxTime])

Move the given display object towards the x/y coordinates at a steady velocity. If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds. Timings are approximate due to the way browser timers work. Allow for a variance of +- 50ms. Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course. Note: The display object doesn't stop moving once it reaches the destination coordinates. Note: Doesn't take into account acceleration, maxVelocity or drag (if you've set drag or acceleration too high this object may not move at all)

Parameters:
Name Type Argument Default Description
displayObject any

The display object to move.

x number

The x coordinate to move towards.

y number

The y coordinate to move towards.

speed number <optional>
60

The speed it will move, in pixels per second (default is 60 pixels/sec)

maxTime number <optional>
0

Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the object will arrive at destination in the given number of ms.

Source:
src/physics/arcade/World.js line 1740
Returns:

The angle (in radians) that the object should be visually set to in order to match its new velocity.

Type
number

overlap(object1, object2 [, overlapCallback] [, processCallback] [, callbackContext])

Checks for overlaps between two game objects. The objects can be Sprites, Groups or Emitters.

Unlike collide the objects are NOT automatically separated or have any physics applied, they merely test for overlap results.

You can perform Sprite vs. Sprite, Sprite vs. Group and Group vs. Group overlap checks. Both the first and second parameter can be arrays of objects, of differing types. If two arrays are passed, the contents of the first parameter will be tested against all contents of the 2nd parameter.

This function is not recursive, and will not test against children of objects passed (i.e. Groups within Groups).

Tilemaps

Any overlapping tiles, including blank/null tiles, will give a positive result. Tiles marked via Phaser.Tilemap#setCollision (and similar methods) have no special status, and callbacks added via Phaser.Tilemap#setTileIndexCallback or Phaser.Tilemap#setTileLocationCallback are not invoked. So calling this method without any callbacks isn't very useful.

If you're interested only in whether an object overlaps a certain tile or class of tiles, filter the tiles with processCallback and then use the result returned by this method. Blank/null tiles can be excluded by their index (-1).

If you want to take action on certain overlaps, examine the tiles in collideCallback and then handle as you like.

Parameters:
Name Type Argument Default Description
object1 Phaser.Sprite | Phaser.Group | Phaser.Particles.Emitter | array

The first object or array of objects to check. Can be Phaser.Sprite, Phaser.Group or Phaser.Particles.Emitter.

object2 Phaser.Sprite | Phaser.Group | Phaser.Particles.Emitter | array

The second object or array of objects to check. Can be Phaser.Sprite, Phaser.Group or Phaser.Particles.Emitter.

overlapCallback function <optional>
null

An optional callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you specified them, unless you are checking Group vs. Sprite, in which case Sprite will always be the first parameter.

processCallback function <optional>
null

A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then overlapCallback will only be called if this callback returns true.

callbackContext object <optional>

The context in which to run the callbacks.

Source:
src/physics/arcade/World.js line 313
Returns:

True if an overlap occurred otherwise false.

Type
boolean

setBounds(x, y, width, height)

Updates the size of this physics world.

Parameters:
Name Type Description
x number

Top left most corner of the world.

y number

Top left most corner of the world.

width number

New width of the world. Can never be smaller than the Game.width.

height number

New height of the world. Can never be smaller than the Game.height.

Source:
src/physics/arcade/World.js line 134

setBoundsToWorld()

Updates the size of this physics world to match the size of the game world.

Source:
src/physics/arcade/World.js line 148

sort(group [, sortDirection])

This method will sort a Groups hash array.

If the Group has physicsSortDirection set it will use the sort direction defined.

Otherwise if the sortDirection parameter is undefined, or Group.physicsSortDirection is null, it will use Phaser.Physics.Arcade.sortDirection.

By changing Group.physicsSortDirection you can customise each Group to sort in a different order.

Parameters:
Name Type Argument Description
group Phaser.Group

The Group to sort.

sortDirection integer <optional>

The sort direction used to sort this Group.

Source:
src/physics/arcade/World.js line 495

sortBottomTop(a, b)

A Sort function for sorting two bodies based on a BOTTOM to TOP sort direction.

This is called automatically by World.sort

Parameters:
Name Type Description
a Phaser.Sprite

The first Sprite to test. The Sprite must have an Arcade Physics Body.

b Phaser.Sprite

The second Sprite to test. The Sprite must have an Arcade Physics Body.

Source:
src/physics/arcade/World.js line 475
Returns:

A negative value if a > b, a positive value if a < b or 0 if a === b or the bodies are invalid.

Type
integer

sortLeftRight(a, b)

A Sort function for sorting two bodies based on a LEFT to RIGHT sort direction.

This is called automatically by World.sort

Parameters:
Name Type Description
a Phaser.Sprite

The first Sprite to test. The Sprite must have an Arcade Physics Body.

b Phaser.Sprite

The second Sprite to test. The Sprite must have an Arcade Physics Body.

Source:
src/physics/arcade/World.js line 415
Returns:

A negative value if a > b, a positive value if a < b or 0 if a === b or the bodies are invalid.

Type
integer

sortRightLeft(a, b)

A Sort function for sorting two bodies based on a RIGHT to LEFT sort direction.

This is called automatically by World.sort

Parameters:
Name Type Description
a Phaser.Sprite

The first Sprite to test. The Sprite must have an Arcade Physics Body.

b Phaser.Sprite

The second Sprite to test. The Sprite must have an Arcade Physics Body.

Source:
src/physics/arcade/World.js line 435
Returns:

A negative value if a > b, a positive value if a < b or 0 if a === b or the bodies are invalid.

Type
integer

sortTopBottom(a, b)

A Sort function for sorting two bodies based on a TOP to BOTTOM sort direction.

This is called automatically by World.sort

Parameters:
Name Type Description
a Phaser.Sprite

The first Sprite to test. The Sprite must have an Arcade Physics Body.

b Phaser.Sprite

The second Sprite to test. The Sprite must have an Arcade Physics Body.

Source:
src/physics/arcade/World.js line 455
Returns:

A negative value if a > b, a positive value if a < b or 0 if a === b or the bodies are invalid.

Type
integer

updateMotion(The)

Called automatically by a Physics body, it updates all motion related values on the Body unless World.isPaused is true.

Parameters:
Name Type Description
The Phaser.Physics.Arcade.Body

Body object to be updated.

Source:
src/physics/arcade/World.js line 234

velocityFromAngle(angle [, speed] [, point])

Given the angle (in degrees) and speed calculate the velocity and return it as a Point object, or set it to the given point object. One way to use this is: velocityFromAngle(angle, 200, sprite.velocity) which will set the values directly to the sprites velocity and not create a new Point object.

Parameters:
Name Type Argument Default Description
angle number

The angle in degrees calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative)

speed number <optional>
60

The speed it will move, in pixels per second sq.

point Phaser.Point | object <optional>

The Point object in which the x and y properties will be set to the calculated velocity.

Source:
src/physics/arcade/World.js line 1774
Returns:
  • A Point where point.x contains the velocity x value and point.y contains the velocity y value.
Type
Phaser.Point

velocityFromRotation(rotation [, speed] [, point])

Given the rotation (in radians) and speed calculate the velocity and return it as a Point object, or set it to the given point object. One way to use this is: velocityFromRotation(rotation, 200, sprite.velocity) which will set the values directly to the sprites velocity and not create a new Point object.

Parameters:
Name Type Argument Default Description
rotation number

The angle in radians.

speed number <optional>
60

The speed it will move, in pixels per second sq.

point Phaser.Point | object <optional>

The Point object in which the x and y properties will be set to the calculated velocity.

Source:
src/physics/arcade/World.js line 1792
Returns:
  • A Point where point.x contains the velocity x value and point.y contains the velocity y value.
Type
Phaser.Point

worldAngleToPointer(displayObject [, pointer])

Find the angle in radians between a display object (like a Sprite) and a Pointer, taking their x/y and center into account relative to the world.

Parameters:
Name Type Argument Description
displayObject any

The DisplayObjerct to test from.

pointer Phaser.Pointer <optional>

The Phaser.Pointer to test to. If none is given then Input.activePointer is used.

Source:
src/physics/arcade/World.js line 2171
Returns:

The angle in radians between displayObject.world.x/y to Pointer.worldX / worldY

Type
number

phaser-ce@2.20.0 is on GitHub and NPM

Documentation generated by JSDoc 3.6.7 on 2022-12-10 using Tomorrow.