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
-
- Source:
Properties:
Name Type Description applyDamping
boolean Enable to automatically apply body damping each step.
-
applyGravity
-
- Source:
Properties:
Name Type Description applyGravity
boolean Enable to automatically apply gravity each step.
-
applySpringForces
-
- Source:
Properties:
Name Type Description applySpringForces
boolean Enable to automatically apply spring forces each step.
-
bounds
-
- Source:
Properties:
Name Type Description bounds
p2.Body The bounds body contains the 4 walls that border the World. Define or disable with setBounds.
-
collisionGroups
-
- Source:
Properties:
Name Type Description collisionGroups
array Internal var.
-
emitImpactEvent
-
- Source:
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.
-
enableBodySleeping
-
- Source:
Properties:
Name Type Description enableBodySleeping
boolean Enable / disable automatic body sleeping.
-
friction
-
- Source:
Properties:
Name Type Description friction
number Friction between colliding bodies. This value is used if no matching ContactMaterial is found for a Material pair.
-
game
-
- Source:
Properties:
Name Type Description game
Phaser.Game Local reference to game.
-
gravity
-
- Source:
Properties:
Name Type Description gravity
Phaser.InversePointProxy The gravity applied to all bodies each step.
-
<protected> materials
-
- Source:
Properties:
Name Type Description materials
array.<Phaser.Physics.Material> A local array of all created Materials.
-
onBeginContact
-
- Source:
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.
-
onBodyAdded
-
- Source:
Properties:
Name Type Description onBodyAdded
Phaser.Signal Dispatched when a new Body is added to the World.
-
onBodyRemoved
-
- Source:
Properties:
Name Type Description onBodyRemoved
Phaser.Signal Dispatched when a Body is removed from the World.
-
onConstraintAdded
-
- Source:
Properties:
Name Type Description onConstraintAdded
Phaser.Signal Dispatched when a new Constraint is added to the World.
-
onConstraintRemoved
-
- Source:
Properties:
Name Type Description onConstraintRemoved
Phaser.Signal Dispatched when a Constraint is removed from the World.
-
onContactMaterialAdded
-
- Source:
Properties:
Name Type Description onContactMaterialAdded
Phaser.Signal Dispatched when a new ContactMaterial is added to the World.
-
onContactMaterialRemoved
-
- Source:
Properties:
Name Type Description onContactMaterialRemoved
Phaser.Signal Dispatched when a ContactMaterial is removed from the World.
-
onEndContact
-
- Source:
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.
-
onImpact
-
- Source:
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.
-
onPostBroadphase
-
- Source:
Properties:
Name Type Description onPostBroadphase
Phaser.Signal Dispatched after the Broadphase has collected collision pairs in the world.
-
onPostStep
-
- Source:
Properties:
Name Type Description onPostStep
Phaser.Signal Dispatched after the World.step()
-
onSpringAdded
-
- Source:
Properties:
Name Type Description onSpringAdded
Phaser.Signal Dispatched when a new Spring is added to the World.
-
onSpringRemoved
-
- Source:
Properties:
Name Type Description onSpringRemoved
Phaser.Signal Dispatched when a Spring is removed from the World.
-
restituion
-
- Source:
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.
-
solveConstraints
-
- Source:
Properties:
Name Type Description solveConstraints
boolean Enable/disable constraint solving in each step.
-
<readonly> time
-
- Source:
Properties:
Name Type Description time
boolean The World time.
-
<protected> world
-
- Source:
Properties:
Name Type Description game
p2.World The p2 World in which the simulation is run.
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.
-
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.
-
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, ...)
wherex
andy
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, ...)
wherex
andy
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.
-
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.
-
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.
-
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.
-
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: