Class: Arcade

Phaser.Physics. Arcade

Arcade Physics Constructor

new Arcade(game)

Arcade Physics constructor.

Parameters:
Name Type Description
game Phaser.Game

reference to the current game instance.

Source:

Classes

Body

Members

<static, constant> CIRCLE :number

Type:
  • number
Source:

<static, constant> POLYGON :number

Type:
  • number
Source:

<static, constant> RECT :number

Type:
  • number
Source:

game

Properties:
Name Type Description
game Phaser.Game

Local reference to game.

Source:

gravity

Properties:
Name Type Description
gravity Phaser.Point

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

Source:

maxLevels

Properties:
Name Type Description
maxLevels number

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

Source:

maxObjects

Properties:
Name Type Description
maxObjects number

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

Source:

quadTree

Properties:
Name Type Description
quadTree Phaser.QuadTree

The world QuadTree.

Source:

worldBottom

Properties:
Name Type Description
worldBottom SAT.Box

The bottom of the physics bounds.

Source:

worldLeft

Properties:
Name Type Description
worldLeft SAT.Box

The left hand side of the physics bounds.

Source:

worldPolys

Properties:
Name Type Description
worldPolys array.<SAT.Polygon>

An array of the polygon data from the physics bounds.

Source:

worldRight

Properties:
Name Type Description
worldRight SAT.Box

The right hand side of the physics bounds.

Source:

worldTop

Properties:
Name Type Description
worldTop SAT.Box

The top side of the physics bounds.

Source:

Methods

accelerateToObject(displayObject, destination, speed, xSpeedMax, ySpeedMax) → {number}

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:
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) → {number}

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:
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) → {number}

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:
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) → {Phaser.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:
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) → {number}

Find the angle in radians between 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:
Returns:

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

Type
number

angleToPointer(displayObject, pointer) → {number}

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

Parameters:
Name Type Argument 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.

Source:
Returns:

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

Type
number

angleToXY(displayObject, x, y) → {number}

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

Parameters:
Name Type 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.

Source:
Returns:

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

Type
number

checkBounds(The) → {boolean}

Checks the given Physics.Body against the Physics Bounds, if any are set, and separates them, setting the blocked flags on the Body as it does so.

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

Body object to be checked.

Source:
Returns:

True if the body hit the bounds, otherwise false.

Type
boolean

collide(object1, object2, collideCallback, processCallback, callbackContext) → {boolean}

Checks for collision between two game objects. You can perform Sprite vs. Sprite, Sprite vs. Group, Group vs. Group, Sprite vs. Tilemap Layer or Group vs. Tilemap Layer collisions. The second parameter can be an array of objects, of differing types. The objects are also automatically separated. If you don't require separation then use ArcadePhysics.overlap instead. 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.

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

The first object to check. Can be an instance of Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter, or Phaser.Tilemap.

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

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

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.

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.

callbackContext object <optional>

The context in which to run the callbacks.

Source:
Returns:

True if a collision occured otherwise false.

Type
boolean

distanceBetween(source, target) → {number}

Find the distance between 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:
Returns:

The distance between the source and target objects.

Type
number

distanceToPointer(displayObject, pointer) → {number}

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 the method distanceBetweenCenters()

Parameters:
Name Type Argument 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.

Source:
Returns:

The distance between the object and the Pointer.

Type
number

distanceToXY(displayObject, x, y) → {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()

Parameters:
Name Type 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.

Source:
Returns:

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

Type
number

intersects(a, b) → {boolean}

Performs a rect intersection test against the two objects. Objects must expose properties: width, height, left, right, top, bottom.

Parameters:
Name Type Description
a object

The first object to test.

b object

The second object to test.

Source:
Returns:

Returns true if the objects intersect, otherwise false.

Type
boolean

moveToObject(displayObject, destination, speed, maxTime) → {number}

Move the given display object towards the destination object 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.

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:
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) → {number}

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:
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) → {number}

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:
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) → {boolean}

Checks for overlaps between two game objects. The objects can be Sprites, Groups or Emitters. You can perform Sprite vs. Sprite, Sprite vs. Group and Group vs. Group overlap checks. Unlike collide the objects are NOT automatically separated or have any physics applied, they merely test for overlap results. The second parameter can be an array of objects, of differing types.

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

The first object to check. Can be an instance of 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.

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 processCallback returns true.

callbackContext object <optional>

The context in which to run the callbacks.

Source:
Returns:

True if an overlap occured otherwise false.

Type
boolean

<protected> processTileSeparation(body1) → {boolean}

Internal function to process the separation of a physics body from a tile.

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

The Body object to separate.

Source:
Returns:

Returns true if separated, false if not.

Type
boolean

separate(body1, body2, processCallback, callbackContext) → {boolean}

The core separation function to separate two physics bodies.

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

The Body object to separate.

body2 Phaser.Physics.Arcade.Body

The Body object to separate.

processCallback function <optional>
null

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

callbackContext object <optional>

The context in which to run the process callback.

Source:
Returns:

Returns true if the bodies collided, otherwise false.

Type
boolean

separateTile(body, tile) → {boolean}

The core separation function to separate a physics body and a tile.

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

The Body object to separate.

tile Phaser.Tile

The tile to collide against.

Source:
Returns:

Returns true if the body was separated, otherwise false.

Type
boolean

setBounds(x, y, width, height, left, right, top, bottom)

Sets the bounds of the Physics world to match the given world pixel dimensions. You can optionally set which 'walls' to create: left, right, top or bottom.

Parameters:
Name Type Argument Default Description
x number

The x coordinate of the top-left corner of the bounds.

y number

The y coordinate of the top-left corner of the bounds.

width number

The width of the bounds.

height number

The height of the bounds.

left boolean <optional>
true

If true will create the left bounds wall.

right boolean <optional>
true

If true will create the right bounds wall.

top boolean <optional>
true

If true will create the top bounds wall.

bottom boolean <optional>
true

If true will create the bottom bounds wall.

Source:

setBoundsToWorld(left, right, top, bottom)

Sets the bounds of the Physics world to match the Game.World. You can optionally set which 'walls' to create: left, right, top or bottom.

Parameters:
Name Type Argument Default Description
left boolean <optional>
true

If true will create the left bounds wall.

right boolean <optional>
true

If true will create the right bounds wall.

top boolean <optional>
true

If true will create the top bounds wall.

bottom boolean <optional>
true

If true will create the bottom bounds wall.

Source:

tileIntersects(body, tile) → {boolean}

Performs a rect intersection test against the two objects. Objects must expose properties: width, height, left, right, top, bottom.

Parameters:
Name Type Description
body object

The Body to test.

tile object

The Tile to test.

Source:
Returns:

Returns true if the objects intersect, otherwise false.

Type
boolean

updateMotion(The)

Called automatically by a Physics body, it updates all motion related values on the Body.

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

Body object to be updated.

Source:

velocityFromAngle(angle, speed, point) → {Phaser.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:
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) → {Phaser.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:
Returns:
  • A Point where point.x contains the velocity x value and point.y contains the velocity y value.
Type
Phaser.Point
Phaser Copyright © 2012-2014 Photon Storm Ltd.
Documentation generated by JSDoc 3.3.0-dev on Mon Feb 24 2014 01:12:29 GMT-0000 (GMT) using the DocStrap template.