new Arcade(game)
Arcade Physics constructor.
Parameters:
| Name | Type | Description |
|---|---|---|
game |
Phaser.Game | reference to the current game instance. |
- Source:
Classes
Members
-
bounds
-
- Source:
Properties:
Name Type Description boundsPhaser.Rectangle The bounds inside of which the physics world exists. Defaults to match the world bounds.
-
game
-
- Source:
Properties:
Name Type Description gamePhaser.Game Local reference to game.
-
gravity
-
- Source:
Properties:
Name Type Description gravityPhaser.Point The World gravity setting. Defaults to x: 0, y: 0, or no gravity.
-
maxLevels
-
- Source:
Properties:
Name Type Description maxLevelsnumber Used by the QuadTree to set the maximum number of iteration levels.
-
maxObjects
-
- Source:
Properties:
Name Type Description maxObjectsnumber Used by the QuadTree to set the maximum number of objects per quad.
-
OVERLAP_BIAS
-
- Source:
Properties:
Name Type Description OVERLAP_BIASnumber A value added to the delta values during collision checks.
-
quadTree
-
- Source:
Properties:
Name Type Description quadTreePhaser.QuadTree The world QuadTree.
-
quadTreeID
-
- Source:
Properties:
Name Type Description quadTreeIDnumber The QuadTree ID.
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 displayObjectany The display object to move.
destinationany The display object to move towards. Can be any object but must have visible x/y properties.
speednumber <optional>
60 The speed it will accelerate in pixels per second.
xSpeedMaxnumber <optional>
500 The maximum x velocity the display object can reach.
ySpeedMaxnumber <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 displayObjectany The display object to move.
pointerPhaser.Pointer <optional>
The pointer to move towards. Defaults to Phaser.Input.activePointer.
speednumber <optional>
60 The speed it will accelerate in pixels per second.
xSpeedMaxnumber <optional>
500 The maximum x velocity the display object can reach.
ySpeedMaxnumber <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 displayObjectany The display object to move.
xnumber The x coordinate to accelerate towards.
ynumber The y coordinate to accelerate towards.
speednumber <optional>
60 The speed it will accelerate in pixels per second.
xSpeedMaxnumber <optional>
500 The maximum x velocity the display object can reach.
ySpeedMaxnumber <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: 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 rotationnumber The angle in radians.
speednumber <optional>
60 The speed it will move, in pixels per second sq.
pointPhaser.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 sourceany The Display Object to test from.
targetany 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 displayObjectany The Display Object to test from.
pointerPhaser.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 displayObjectany The Display Object to test from.
xnumber The x coordinate to get the angle to.
ynumber The y coordinate to get the angle to.
- Source:
Returns:
The angle in radians between displayObject.x/y to Pointer.x/y
- Type
- number
-
<protected> checkWorldBounds()
-
Internal method.
- Source:
-
collide(object1, object2, collideCallback, processCallback, callbackContext) → {number}
-
Checks for collision between two game objects. The objects can be Sprites, Groups, Emitters or Tilemaps. You can perform Sprite vs. Sprite, Sprite vs. Group, Group vs. Group, Sprite vs. Tilemap or Group vs. Tilemap collisions. The objects are also automatically separated.
Parameters:
Name Type Argument Default Description object1Phaser.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
object2Phaser.Sprite | Phaser.Group | Phaser.Particles.Emitter | Phaser.Tilemap The second object to check. Can be an instance of Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter or Phaser.Tilemap
collideCallbackfunction <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 passed them to Collision.overlap.
processCallbackfunction <optional>
null A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then collideCallback will only be called if processCallback returns true.
callbackContextobject <optional>
The context in which to run the callbacks.
- Source:
Returns:
The number of collisions that were processed.
- Type
- number
-
computeVelocity(axis, body, velocity, acceleration, drag, mMax) → {number}
-
A tween-like function that takes a starting velocity and some other factors and returns an altered velocity.
Parameters:
Name Type Description axisnumber 1 for horizontal, 2 for vertical.
bodyPhaser.Physics.Arcade.Body The Body object to be updated.
velocitynumber Any component of velocity (e.g. 20).
accelerationnumber Rate at which the velocity is changing.
dragnumber Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set.
mMaxnumber An absolute value cap for the velocity.
- Source:
Returns:
The altered Velocity value.
- Type
- number
-
distanceBetween(source, target) → {number}
-
Find the distance between two display objects (like Sprites).
Parameters:
Name Type Description sourceany The Display Object to test from.
targetany 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 displayObjectany The Display Object to test from.
pointerPhaser.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 displayObjectany The Display Object to test from.
xnumber The x coordinate to move towards.
ynumber The y coordinate to move towards.
- Source:
Returns:
The distance between the object and the x/y coordinates.
- Type
- number
-
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 displayObjectany The display object to move.
destinationany The display object to move towards. Can be any object but must have visible x/y properties.
speednumber <optional>
60 The speed it will move, in pixels per second (default is 60 pixels/sec)
maxTimenumber <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 displayObjectany The display object to move.
speednumber <optional>
60 The speed it will move, in pixels per second (default is 60 pixels/sec)
pointerPhaser.Pointer <optional>
The pointer to move towards. Defaults to Phaser.Input.activePointer.
maxTimenumber <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 displayObjectany The display object to move.
xnumber The x coordinate to move towards.
ynumber The y coordinate to move towards.
speednumber <optional>
60 The speed it will move, in pixels per second (default is 60 pixels/sec)
maxTimenumber <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) → {boolean}
-
Checks if two Sprite objects overlap.
Parameters:
Name Type Description object1Phaser.Sprite The first object to check. Can be an instance of Phaser.Sprite or anything that extends it.
object2Phaser.Sprite The second object to check. Can be an instance of Phaser.Sprite or anything that extends it.
- Source:
Returns:
true if the two objects overlap.
- Type
- boolean
-
<protected> postUpdate()
-
Called automatically by the core game loop.
- Source:
-
<protected> postUpdate()
-
Internal method.
- Source:
-
<protected> preUpdate()
-
Called automatically by the core game loop.
- Source:
-
<protected> preUpdate()
-
Internal method.
- Source:
-
reset()
-
Resets all Body values (velocity, acceleration, rotation, etc)
- Source:
-
separate(body1, body2) → {boolean}
-
The core separation function to separate two physics bodies.
Parameters:
Name Type Description body1Phaser.Physics.Arcade.Body The Body object to separate.
body2Phaser.Physics.Arcade.Body The Body object to separate.
- Source:
Returns:
Returns true if the bodies were separated, otherwise false.
- Type
- boolean
-
separateTile(body1, tile) → {boolean}
-
The core separation function to separate a physics body and a tile.
Parameters:
Name Type Description body1Phaser.Physics.Arcade.Body The Body object to separate.
tilePhaser.Tile The tile to collide against.
- Source:
Returns:
Returns true if the bodies were separated, otherwise false.
- Type
- boolean
-
separateTileX(body1, tile) → {boolean}
-
The core separation function to separate a physics body and a tile on the x axis.
Parameters:
Name Type Description body1Phaser.Physics.Arcade.Body The Body object to separate.
tilePhaser.Tile The tile to collide against.
- Source:
Returns:
Returns true if the bodies were separated, otherwise false.
- Type
- boolean
-
separateTileY(body1, tile) → {boolean}
-
The core separation function to separate a physics body and a tile on the x axis.
Parameters:
Name Type Description body1Phaser.Physics.Arcade.Body The Body object to separate.
tilePhaser.Tile The tile to collide against.
- Source:
Returns:
Returns true if the bodies were separated, otherwise false.
- Type
- boolean
-
separateX(body1, body2) → {boolean}
-
The core separation function to separate two physics bodies on the x axis.
Parameters:
Name Type Description body1Phaser.Physics.Arcade.Body The Body object to separate.
body2Phaser.Physics.Arcade.Body The Body object to separate.
- Source:
Returns:
Returns true if the bodies were separated, otherwise false.
- Type
- boolean
-
separateY(body1, body2) → {boolean}
-
The core separation function to separate two physics bodies on the y axis.
Parameters:
Name Type Description body1Phaser.Physics.Arcade.Body The Body object to separate.
body2Phaser.Physics.Arcade.Body The Body object to separate.
- Source:
Returns:
Returns true if the bodies were separated, otherwise false.
- Type
- boolean
-
setSize(width, height, offsetX, offsetY)
-
You can modify the size of the physics Body to be any dimension you need. So it could be smaller or larger than the parent Sprite. You can also control the x and y offset, which is the position of the Body relative to the top-left of the Sprite.
Parameters:
Name Type Description widthnumber The width of the Body.
heightnumber The height of the Body.
offsetXnumber The X offset of the Body from the Sprite position.
offsetYnumber The Y offset of the Body from the Sprite position.
- Source:
-
<protected> updateBounds()
-
Internal method.
- Source:
-
<protected> updateHulls()
-
Internal method.
- Source:
-
updateMotion(The)
-
Called automatically by a Physics body, it updates all motion related values on the Body.
Parameters:
Name Type Description ThePhaser.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 anglenumber The angle in degrees calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative)
speednumber <optional>
60 The speed it will move, in pixels per second sq.
pointPhaser.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 rotationnumber The angle in radians.
speednumber <optional>
60 The speed it will move, in pixels per second sq.
pointPhaser.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