World

arcade.World (Class) → ceramic.ArcadeWorld

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

Instance Members

arcade
gravityX: Float

The World gravity X setting. Defaults to 0 (no gravity).


arcade
gravityY: Float

The World gravity Y setting. Defaults to 0 (no gravity).


arcade
boundsX: Float

The bounds x position inside of which the physics world exists.


arcade
boundsY: Float

The bounds y position inside of which the physics world exists.


arcade
boundsWidth: Float

The bounds width inside of which the physics world exists.


arcade
boundsHeight: Float

The bounds height inside of which the physics world exists.


arcade
checkCollisionNone: Bool

Which edges of the World bounds Bodies can collide against when collideWorldBounds is true. For example checkCollisionDown = false means Bodies cannot collide with the World.bounds.bottom.


arcade
checkCollisionUp: Bool

Whether Bodies can collide with the World upper bounds.


arcade
checkCollisionDown: Bool

Whether Bodies can collide with the World lower bounds.


arcade
checkCollisionLeft: Bool

Whether Bodies can collide with the World left bounds.


arcade
checkCollisionRight: Bool

Whether Bodies can collide with the World right bounds.


arcade
maxObjects: Int

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


arcade
maxLevels: Int

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


arcade
overlapBias: Float

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


arcade
forceX: Bool

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


arcade
sortDirection: SortDirection

Used when colliding a Body vs. a Group, or a Group vs. a Group, this defines the direction the sort is based on. Default is LEFT_RIGHT.


arcade
skipQuadTree: Bool

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.


arcade
isPaused: Bool

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.


arcade
maxObjectsWithoutQuadTree: Int

When colliding/overlapping with groups. Use a quad tree if we reach this threshold value


arcade
tileBias: Float

A value added to the delta values during collision with tiles. Adjust this if you get tunneling.


arcade
elapsed: Float

Elapsed time since last tick.


arcade
elapsedMS: Float

arcade
getQuadTree(): QuadTree

Get a QuadTree object configured for this world. IMPORTANT: you must release it with releaseQuadTree() when you are done using it and the items it returned.

Returns Description
QuadTree QuadTree

arcade
releaseQuadTree(quadTree: QuadTree): Void
Name Type
quadTree QuadTree

arcade
setBounds(x: Float, y: Float, width: Float, height: Float): Void

Updates the size of this physics world.

Name Type Description
x Float Top left most corner of the world.
y Float Top left most corner of the world.
width Float New width of the world.
height Float New height of the world.

arcade
enableBody(body: Body): Void

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.

Name Type Description
body Body The body to enable.

arcade
updateMotion(body: Body): Void

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

Name Type Description
body Body The Body object to be updated.

arcade
computeVelocity(axis: Axis, body: Body, velocity: Float, acceleration: Float, drag: Float, ?max: Float = 10000): Float

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

Name Type Default Description
axis Axis 0 for nothing, 1 for horizontal, 2 for vertical.
body Body The Body object to be updated.
velocity Float Any component of velocity (e.g. 20).
acceleration Float Rate at which the velocity is changing.
drag Float Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set.
max Float 10000 An absolute value cap for the velocity.
Returns Description
Float The altered Velocity value.

arcade
overlap(element1: Collidable, ?element2: Collidable, ?collideCallback: Function, ?processCallback: Function): Bool
Name Type Default
element1 Collidable
element2 Collidable (optional)
collideCallback Function (optional)
processCallback Function (optional)
Returns
Bool

arcade
overlapBodyVsBody(body1: Body, body2: Body, ?overlapCallback: Function, ?processCallback: Function): Bool

Checks for overlaps between two bodies. The objects can be Bodies or Groups. Unlike collide the objects are NOT automatically separated or have any physics applied, they merely test for overlap results.

Name Type Default
body1 Body
body2 Body
overlapCallback Function (optional)
processCallback Function (optional)
Returns Description
Bool True if an overlap occurred otherwise false.

arcade
overlapGroupVsGroup(group1: Group, group2: Group, ?overlapCallback: Function, ?processCallback: Function): Bool
Name Type Default
group1 Group
group2 Group
overlapCallback Function (optional)
processCallback Function (optional)
Returns
Bool

arcade
overlapGroupVsItself(group: Group, ?overlapCallback: Function, ?processCallback: Function): Bool
Name Type Default
group Group
overlapCallback Function (optional)
processCallback Function (optional)
Returns
Bool

arcade
overlapBodyVsGroup(body: Body, group: Group, ?overlapCallback: Function, ?processCallback: Function): Bool
Name Type Default
body Body
group Group
overlapCallback Function (optional)
processCallback Function (optional)
Returns
Bool

arcade
collide(element1: Collidable, ?element2: Collidable, ?collideCallback: Function, ?processCallback: Function): Bool
Name Type Default
element1 Collidable
element2 Collidable (optional)
collideCallback Function (optional)
processCallback Function (optional)
Returns
Bool

arcade
collideBodyVsBody(body1: Body, body2: Body, ?collideCallback: Function, ?processCallback: Function): Bool

Checks for collision between two bodies and separates them if colliding. If you don't require separation then use overlap instead.

Name Type Default
body1 Body
body2 Body
collideCallback Function (optional)
processCallback Function (optional)
Returns Description
Bool True if a collision occurred otherwise false.

arcade
collideGroupVsGroup(group1: Group, group2: Group, ?collideCallback: Function, ?processCallback: Function): Bool
Name Type Default
group1 Group
group2 Group
collideCallback Function (optional)
processCallback Function (optional)
Returns
Bool

arcade
collideGroupVsItself(group: Group, ?collideCallback: Function, ?processCallback: Function): Bool
Name Type Default
group Group
collideCallback Function (optional)
processCallback Function (optional)
Returns
Bool

arcade
collideBodyVsGroup(body: Body, group: Group, ?collideCallback: Function, ?processCallback: Function): Bool
Name Type Default
body Body
group Group
collideCallback Function (optional)
processCallback Function (optional)
Returns
Bool

arcade
sort(group: Group, ?sortDirection: SortDirection = SortDirection.INHERIT): Void

This method will sort a Groups hash array.

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

Otherwise if the sortDirection parameter is undefined, or Group.sortDirection is null, it will use World.sortDirection.

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

Name Type Default Description
group Group The Group to sort.
sortDirection SortDirection SortDirection.INHERIT The sort direction used to sort this Group.

arcade
intersects(body1: Body, body2: Body): Bool

Check for intersection against two bodies.

Name Type Description
body1 Body The first Body object to check.
body2 Body The second Body object to check.
Returns Description
Bool True if they intersect, otherwise false.

arcade
getObjectsAtLocation(x: Float, y: Float, group: Group, ?callback: Function, ?callbackArg: getObjectsAtLocation.T, ?output: Array<Body>): Array<Body>

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.

Name Type Default Description
x Float The x coordinate to check.
y Float The y coordinate to check.
group 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 Body that overlapped the location.
callbackArg getObjectsAtLocation.T (optional) An argument to pass to the callback.
output Array<Body> (optional) An optional array to store the results in.
Returns Description
Array<Body> An array of the Bodies from the Group that overlapped the coordinates.

arcade
moveToDestination(body: Body, destination: Body, ?speed: Float = 60, ?maxTime: Float = 0): Float

Move the given body towards the destination body 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 body does not continuously track the target. If the target changes location during transit the body will not modify its course. Note: The body 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)

Name Type Default Description
body Body The body to move.
destination Body The body to move towards. Must have x/y properties.
speed Float 60 The speed it will move, in pixels per second (default is 60 pixels/sec)
maxTime Float 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.
Returns Description
Float The angle (in radians) that the object should be visually set to in order to match its new velocity.

arcade
moveToXY(body: Body, x: Float, y: Float, ?speed: Float = 60, ?maxTime: Float = 0): Float

Move the given body 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 body does not continuously track the target. If the target changes location during transit the body will not modify its course. Note: The body 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)

Name Type Default Description
body Body The body to move.
x Float The x coordinate to move towards.
y Float The y coordinate to move towards.
speed Float 60 The speed it will move, in pixels per second (default is 60 pixels/sec)
maxTime Float 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.
Returns Description
Float The angle (in radians) that the object should be visually set to in order to match its new velocity.

arcade
velocityFromAngle(angle: Float, ?speed: Float = 60, ?point: Point): 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, point) which will set the values directly to the point and not create a new Point object.

Name Type Default Description
angle Float The angle in degrees calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative)
speed Float 60 The speed it will move, in pixels per second sq.
point Point (optional) The Point object in which the x and y properties will be set to the calculated velocity.
Returns Description
Point A Point where point.x contains the velocity x value and point.y contains the velocity y value.

arcade
velocityFromRotation(rotation: Float, ?speed: Float = 60, ?point: Point): 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, point) which will set the values directly to the point and not create a new Point object.

Name Type Default Description
rotation Float The angle in radians.
speed Float 60 The speed it will move, in pixels per second sq.
point Point (optional) The Point object in which the x and y properties will be set to the calculated velocity.
Returns Description
Point A Point where point.x contains the velocity x value and point.y contains the velocity y value.

arcade
accelerationFromRotation(rotation: Float, ?speed: Float = 60, ?point: Point): 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, point) which will set the values directly to the point and not create a new Point object.

Name Type Default Description
rotation Float The angle in radians.
speed Float 60 The speed it will move, in pixels per second sq.
point Point (optional) The Point object in which the x and y properties will be set to the calculated acceleration.
Returns Description
Point A Point where point.x contains the acceleration x value and point.y contains the acceleration y value.

arcade
accelerateToDestination(body: Body, destination: Body, ?speed: Float = 60, ?xSpeedMax: Float = 1000, ?ySpeedMax: Float = 1000): Float

Sets the acceleration.x/y property on the body 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 body won't go any faster. Note: The body does not continuously track the target. If the target changes location during transit the body will not modify its course. Note: The body doesn't stop moving once it reaches the destination coordinates.

Name Type Default Description
body Body The body to move.
destination Body The body to move towards. Must have x/y properties.
speed Float 60 The speed it will accelerate in pixels per second.
xSpeedMax Float 1000 The maximum x velocity the body can reach.
ySpeedMax Float 1000 The maximum y velocity the body can reach.
Returns Description
Float The angle (in radians) that the object should be visually set to in order to match its new trajectory.

arcade
accelerateToXY(body: Body, x: Float, y: Float, ?speed: Float = 60, ?xSpeedMax: Float = 1000, ?ySpeedMax: Float = 1000): Float

Sets the acceleration.x/y property on the body 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 body won't go any faster. Note: The body does not continuously track the target. If the target changes location during transit the body will not modify its course. Note: The body doesn't stop moving once it reaches the destination coordinates.

Name Type Default Description
body Body The body to move.
x Float The x coordinate to accelerate towards.
y Float The y coordinate to accelerate towards.
speed Float 60 The speed it will accelerate in pixels per second.
xSpeedMax Float 1000 The maximum x velocity the body can reach.
ySpeedMax Float 1000 The maximum y velocity the body can reach.
Returns Description
Float The angle (in radians) that the object should be visually set to in order to match its new trajectory.

arcade
distanceBetween(source: Body, target: Body, ?useCenter: Bool = false): Float

Find the distance between two bodies.

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

Name Type Default Description
source Body The Body to test from.
target Body The Body to test to.
useCenter Bool false Calculate the distance using the centerX and centerY coordinates.
Returns Description
Float The distance between the source and target objects.

arcade
distanceToXY(body: Body, x: Float, y: Float): Float

Find the distance between a body and the given x/y coordinates. The calculation is made from the body's x/y coordinate. This may be the top-left. If you need to calculate from the center of a body instead use distanceBetween with the useCenter argument.

Name Type Description
body Body The Body to test from.
x Float The x coordinate to move towards.
y Float The y coordinate to move towards.
Returns Description
Float The distance between the object and the x/y coordinates.

arcade
closest(source: Body, targets: Array<Body>, ?world: Bool = false, ?useCenter: Bool = false): Body

From a set of bodies, find the one closest to a source body.

Name Type Default Description
source Body The Body distances will be measured from.
targets Array<Body> The Bodies whose distances to the source will be compared.
world Bool false Calculate the distance using World coordinates (true), or Object coordinates (false, the default). If useCenter is true, this value is ignored.
useCenter Bool false Calculate the distance using the centerX and centerY coordinates. If true, this value overrides the world argument.
Returns Description
Body The first target closest to the origin.

arcade
farthest(source: Body, targets: Array<Body>, ?useCenter: Bool = false): Body

From a set of bodies, find the one farthest from a source body.

Name Type Default Description
source Body The Body distances will be measured from.
targets Array<Body> The Bodies whose distances to the source will be compared.
useCenter Bool false Calculate the distance using the centerX and centerY coordinates.
Returns Description
Body The target farthest from the origin.

arcade
angleBetween(source: Body, target: Body): Float

Find the angle in radians between two bodies.

Name Type Description
source Body The Body to test from.
target Body The Body to test to.
Returns Description
Float The angle in radians between the source and target bodies.

arcade
angleBetweenCenters(source: Body, target: Body): Float

Find the angle in radians between centers of two bodies.

Name Type Description
source Body The Body to test from.
target Body The Body to test to.
Returns Description
Float The angle in radians between the source and target bodies.

arcade
angleToXY(body: Body, x: Float, y: Float): Float

Find the angle in radians between a body and the given x/y coordinate.

Name Type Description
body Body The Body to test from.
x Float The x coordinate to get the angle to.
y Float The y coordinate to get the angle to.
Returns Description
Float The angle in radians between body.x/y to x/y

arcade
new(boundsX: Float, boundsY: Float, boundsWidth: Float, boundsHeight: Float): Void
Name Type
boundsX Float
boundsY Float
boundsWidth Float
boundsHeight Float

Private Members

arcade
HALF_PI: Float

arcade
quadTrees: Array<QuadTree>

The world QuadTree objects.


arcade
quadTreePool: QuadTreePool

A shared internal pool used by every QuadTree.


arcade
distance(x1: Float, y1: Float, x2: Float, y2: Float): Float
Name Type
x1 Float
y1 Float
x2 Float
y2 Float
Returns
Float

arcade
clamp(v: Float, min: Float, max: Float): Float
Name Type
v Float
min Float
max Float
Returns
Float

arcade
getCollidableType(element: Collidable): Class<Dynamic>
Name Type
element Collidable
Returns
Class<Dynamic>

arcade
separate(body1: Body, body2: Body, ?processCallback: Function, overlapOnly: Bool): Bool

The core separation function to separate two physics bodies.

Name Type Default Description
body1 Body The first Body object to separate.
body2 Body The second Body object to separate.
processCallback Function (optional) A callback function that lets you perform additional checks against the two objects if they overlap. If this function is set then the bodies will only be collided if it returns true.
overlapOnly Bool Just run an overlap or a full collision.
Returns Description
Bool Returns true if the bodies collided, otherwise false.

arcade
circleBodyIntersects(circle: Body, body: Body): Bool

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

Name Type Description
circle Body The Body with isCircle set.
body Body The Body with isCircle not set (i.e. uses Rectangle shape)
Returns Description
Bool Returns true if the bodies intersect, otherwise false.

arcade
separateCircle(body1: Body, body2: Body, overlapOnly: Bool): Bool

The core separation function to separate two circular physics bodies.

Name Type Description
body1 Body The first Body to separate. Must have Body.isCircle true and a positive radius.
body2 Body The second Body to separate. Must have Body.isCircle true and a positive radius.
overlapOnly Bool If true the bodies will only have their overlap data set, no separation or exchange of velocity will take place.
Returns Description
Bool Returns true if the bodies were separated or overlap, otherwise false.

arcade
getOverlapX(body1: Body, body2: Body, ?overlapOnly: Bool = false): Float

Calculates the horizontal overlap between two Bodies and sets their properties accordingly, including: touchingLeft, touchingRight and overlapX.

Name Type Default Description
body1 Body The first Body to separate.
body2 Body The second Body to separate.
overlapOnly Bool false Is this an overlap only check, or part of separation?
Returns Description
Float Returns the amount of horizontal overlap between the two bodies.

arcade
getOverlapY(body1: Body, body2: Body, ?overlapOnly: Bool = false): Float

Calculates the vertical overlap between two Bodies and sets their properties accordingly, including: touchingUp, touchingDown and overlapY.

Name Type Default Description
body1 Body The first Body to separate.
body2 Body The second Body to separate.
overlapOnly Bool false Is this an overlap only check, or part of separation?
Returns Description
Float Returns the amount of vertical overlap between the two bodies.

arcade
separateX(body1: Body, body2: Body, overlapOnly: Bool): Bool

The core separation function to separate two physics bodies on the x axis.

Name Type Description
body1 Body The first Body to separate.
body2 Body The second Body to separate.
overlapOnly Bool If true the bodies will only have their overlap data set, no separation or exchange of velocity will take place.
Returns Description
Bool Returns true if the bodies were separated or overlap, otherwise false.

arcade
separateY(body1: Body, body2: Body, overlapOnly: Bool): Bool

The core separation function to separate two physics bodies on the y axis.

Name Type Description
body1 Body The first Body to separate.
body2 Body The second Body to separate.
overlapOnly Bool If true the bodies will only have their overlap data set, no separation or exchange of velocity will take place.
Returns Description
Bool Returns true if the bodies were separated or overlap, otherwise false.

arcade
toString(): String
Returns
String