Class: World

Phaser.Physics. World

Physics World Constructor

new World(game, config)

Parameters:
Name Type Argument Description
game Phaser.Game

Reference to the current game instance.

config object <optional>

Physics configuration object passed in from the game constructor.

Source:

Members

applyDamping

Properties:
Name Type Description
applyDamping boolean

Enable to automatically apply body damping each step.

Source:

applyGravity

Properties:
Name Type Description
applyGravity boolean

Enable to automatically apply gravity each step.

Source:

applySpringForces

Properties:
Name Type Description
applySpringForces boolean

Enable to automatically apply spring forces each step.

Source:

bounds

Properties:
Name Type Description
bounds p2.Body

The bounds body contains the 4 walls that border the World. Define or disable with setBounds.

Source:

collisionGroups

Properties:
Name Type Description
collisionGroups array

Internal var.

Source:

emitImpactEvent

Properties:
Name Type Description
emitImpactEvent boolean

Set to true if you want to the world to emit the "impact" event. Turning this off could improve performance.

Source:

enableBodySleeping

Properties:
Name Type Description
enableBodySleeping boolean

Enable / disable automatic body sleeping.

Source:

friction

Properties:
Name Type Description
friction number

Friction between colliding bodies. This value is used if no matching ContactMaterial is found for a Material pair.

Source:

game

Properties:
Name Type Description
game Phaser.Game

Local reference to game.

Source:

gravity

Properties:
Name Type Description
gravity Phaser.InversePointProxy

The gravity applied to all bodies each step.

Source:

<protected> materials

Properties:
Name Type Description
materials array.<Phaser.Physics.Material>

A local array of all created Materials.

Source:

onBeginContact

Properties:
Name Type Description
onBeginContact Phaser.Signal

Dispatched when a first contact is created between two bodies. This event is fired before the step has been done.

Source:

onBodyAdded

Properties:
Name Type Description
onBodyAdded Phaser.Signal

Dispatched when a new Body is added to the World.

Source:

onBodyRemoved

Properties:
Name Type Description
onBodyRemoved Phaser.Signal

Dispatched when a Body is removed from the World.

Source:

onConstraintAdded

Properties:
Name Type Description
onConstraintAdded Phaser.Signal

Dispatched when a new Constraint is added to the World.

Source:

onConstraintRemoved

Properties:
Name Type Description
onConstraintRemoved Phaser.Signal

Dispatched when a Constraint is removed from the World.

Source:

onContactMaterialAdded

Properties:
Name Type Description
onContactMaterialAdded Phaser.Signal

Dispatched when a new ContactMaterial is added to the World.

Source:

onContactMaterialRemoved

Properties:
Name Type Description
onContactMaterialRemoved Phaser.Signal

Dispatched when a ContactMaterial is removed from the World.

Source:

onEndContact

Properties:
Name Type Description
onEndContact Phaser.Signal

Dispatched when final contact occurs between two bodies. This event is fired before the step has been done.

Source:

onImpact

Properties:
Name Type Description
onImpact Phaser.Signal

Dispatched when a first contact is created between two bodies. This event is fired after the step has been done.

Source:

onPostBroadphase

Properties:
Name Type Description
onPostBroadphase Phaser.Signal

Dispatched after the Broadphase has collected collision pairs in the world.

Source:

onPostStep

Properties:
Name Type Description
onPostStep Phaser.Signal

Dispatched after the World.step()

Source:

onSpringAdded

Properties:
Name Type Description
onSpringAdded Phaser.Signal

Dispatched when a new Spring is added to the World.

Source:

onSpringRemoved

Properties:
Name Type Description
onSpringRemoved Phaser.Signal

Dispatched when a Spring is removed from the World.

Source:

restituion

Properties:
Name Type Description
restitution number

Default coefficient of restitution between colliding bodies. This value is used if no matching ContactMaterial is found for a Material pair.

Source:

solveConstraints

Properties:
Name Type Description
solveConstraints boolean

Enable/disable constraint solving in each step.

Source:

<readonly> time

Properties:
Name Type Description
time boolean

The World time.

Source:

<protected> world

Properties:
Name Type Description
game p2.World

The p2 World in which the simulation is run.

Source:

Methods

addBody(body) → {boolean}

Add a body to the world.

Parameters:
Name Type Description
body Phaser.Physics.Body

The Body to add to the World.

Source:
Returns:

True if the Body was added successfully, otherwise false.

Type
boolean

addConstraint(constraint) → {Phaser.Physics.Constraint}

Adds a Constraint to the world.

Parameters:
Name Type Description
constraint Phaser.Physics.Constraint

The Constraint to add to the World.

Source:
Returns:

The Constraint that was added.

Type
Phaser.Physics.Constraint

addContactMaterial(material) → {Phaser.Physics.ContactMaterial}

Adds a Contact Material to the world.

Parameters:
Name Type Description
material Phaser.Physics.ContactMaterial

The Contact Material to be added to the World.

Source:
Returns:

The Contact Material that was added.

Type
Phaser.Physics.ContactMaterial

addSpring(spring) → {Phaser.Physics.Spring}

Adds a Spring to the world.

Parameters:
Name Type Description
spring Phaser.Physics.Spring

The Spring to add to the World.

Source:
Returns:

The Spring that was added.

Type
Phaser.Physics.Spring

createBody(x, y, mass, addToWorld, options, points)

Parameters:
Name Type Argument Default Description
x number

The x coordinate of Body.

y number

The y coordinate of Body.

mass number

The mass of the Body. A mass of 0 means a 'static' Body is created.

addToWorld boolean <optional>
false

Automatically add this Body to the world? (usually false as it won't have any shapes on construction).

options object

An object containing the build options:

Properties
Name Type Argument Default Description
optimalDecomp boolean <optional>
false

Set to true if you need optimal decomposition. Warning: very slow for polygons with more than 10 vertices.

skipSimpleCheck boolean <optional>
false

Set to true if you already know that the path is not intersecting itself.

removeCollinearPoints boolean | number <optional>
false

Set to a number (angle threshold value) to remove collinear points, or false to keep all points.

points Array.<number> | number

An array of 2d vectors that form the convex or concave polygon. Either [[0,0], [0,1],...] or a flat array of numbers that will be interpreted as [x,y, x,y, ...], or the arguments passed can be flat x,y values e.g. setPolygon(options, x,y, x,y, x,y, ...) where x and y are numbers.

Source:

createBody(x, y, mass, addToWorld, options, points)

Parameters:
Name Type Argument Default Description
x number

The x coordinate of Body.

y number

The y coordinate of Body.

mass number

The mass of the Body. A mass of 0 means a 'static' Body is created.

addToWorld boolean <optional>
false

Automatically add this Body to the world? (usually false as it won't have any shapes on construction).

options object

An object containing the build options:

Properties
Name Type Argument Default Description
optimalDecomp boolean <optional>
false

Set to true if you need optimal decomposition. Warning: very slow for polygons with more than 10 vertices.

skipSimpleCheck boolean <optional>
false

Set to true if you already know that the path is not intersecting itself.

removeCollinearPoints boolean | number <optional>
false

Set to a number (angle threshold value) to remove collinear points, or false to keep all points.

points Array.<number> | number

An array of 2d vectors that form the convex or concave polygon. Either [[0,0], [0,1],...] or a flat array of numbers that will be interpreted as [x,y, x,y, ...], or the arguments passed can be flat x,y values e.g. setPolygon(options, x,y, x,y, x,y, ...) where x and y are numbers.

Source:

createContactMaterial(materialA, materialB, options) → {Phaser.Physics.ContactMaterial}

Creates a Contact Material from the two given Materials. You can then edit the properties of the Contact Material directly.

Parameters:
Name Type Argument Description
materialA Phaser.Physics.Material <optional>

The first Material to create the ContactMaterial from. If undefined it will create a new Material object first.

materialB Phaser.Physics.Material <optional>

The second Material to create the ContactMaterial from. If undefined it will create a new Material object first.

options object <optional>

Material options object.

Source:
Returns:

The Contact Material that was created.

Type
Phaser.Physics.ContactMaterial

createMaterial(name, body) → {Phaser.Physics.Material}

Creates a Material. Materials are applied to Shapes owned by a Body and can be set with Body.setMaterial(). Materials are a way to control what happens when Shapes collide. Combine unique Materials together to create Contact Materials. Contact Materials have properties such as friction and restitution that allow for fine-grained collision control between different Materials.

Parameters:
Name Type Argument Description
name string <optional>

Optional name of the Material. Each Material has a unique ID but string names are handy for debugging.

body Phaser.Physics.Body <optional>

Optional Body. If given it will assign the newly created Material to the Body shapes.

Source:
Returns:

The Material that was created. This is also stored in Phaser.Physics.World.materials.

Type
Phaser.Physics.Material

destroy()

Source:

getBodies() → {array.<Phaser.Physics.Body>}

Populates and returns an array of all current Bodies in the world.

Source:
Returns:

An array containing all current Bodies in the world.

Type
array.<Phaser.Physics.Body>

getConstraints() → {array.<Phaser.Physics.Constraints>}

Populates and returns an array of all current Constraints in the world.

Source:
Returns:

An array containing all current Constraints in the world.

Type
array.<Phaser.Physics.Constraints>

getContactMaterial(materialA, materialB) → {Phaser.Physics.ContactMaterial|boolean}

Gets a Contact Material based on the two given Materials.

Parameters:
Name Type Description
materialA Phaser.Physics.Material

The first Material to search for.

materialB Phaser.Physics.Material

The second Material to search for.

Source:
Returns:

The Contact Material or false if none was found matching the Materials given.

Type
Phaser.Physics.ContactMaterial | boolean

getSprings() → {array.<Phaser.Physics.Spring>}

Populates and returns an array of all current Springs in the world.

Source:
Returns:

An array containing all current Springs in the world.

Type
array.<Phaser.Physics.Spring>

hitTest(worldPoint, bodies, precision) → {Array}

Test if a world point overlaps bodies.

Parameters:
Name Type Description
worldPoint Phaser.Point

Point to use for intersection tests.

bodies Array

A list of objects to check for intersection.

precision number

Used for matching against particles and lines. Adds some margin to these infinitesimal objects.

Source:
Returns:

Array of bodies that overlap the point.

Type
Array

removeBody(body) → {Phaser.Physics.Body}

Removes a body from the world.

Parameters:
Name Type Description
body Phaser.Physics.Body

The Body to remove from the World.

Source:
Returns:

The Body that was removed.

Type
Phaser.Physics.Body

removeConstraint(constraint) → {Phaser.Physics.Constraint}

Removes a Constraint from the world.

Parameters:
Name Type Description
constraint Phaser.Physics.Constraint

The Constraint to be removed from the World.

Source:
Returns:

The Constraint that was removed.

Type
Phaser.Physics.Constraint

removeContactMaterial(material) → {Phaser.Physics.ContactMaterial}

Removes a Contact Material from the world.

Parameters:
Name Type Description
material Phaser.Physics.ContactMaterial

The Contact Material to be removed from the World.

Source:
Returns:

The Contact Material that was removed.

Type
Phaser.Physics.ContactMaterial

removeSpring(spring) → {Phaser.Physics.Spring}

Removes a Spring from the world.

Parameters:
Name Type Description
spring Phaser.Physics.Spring

The Spring to remove from the World.

Source:
Returns:

The Spring that was removed.

Type
Phaser.Physics.Spring

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

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.

setCollisionGroup boolean <optional>
true

If true the Bounds will be set to use its own Collision Group.

Source:

setMaterial(material, bodies)

Sets the given Material against all Shapes owned by all the Bodies in the given array.

Parameters:
Name Type Description
material Phaser.Physics.Material

The Material to be applied to the given Bodies.

bodies array.<Phaser.Physics.Body>

An Array of Body objects that the given Material will be set on.

Source:

toJSON() → {object}

Converts the current world into a JSON object.

Source:
Returns:

A JSON representation of the world.

Type
object

update()

Source:
Phaser Copyright © 2012-2014 Photon Storm Ltd.
Documentation generated by JSDoc 3.3.0-dev on Mon Feb 24 2014 12:11:43 GMT-0000 (GMT) using the DocStrap template.