- Matter.World
- Methods
- Matter.World.add
- Matter.World.addBody
- Matter.World.addComposite
- Matter.World.addConstraint
- Matter.Composite.allBodies
- Matter.Composite.allComposites
- Matter.Composite.allConstraints
- Matter.Composite.bounds
- Matter.World.clear
- Matter.World.create
- Matter.Composite.get
- Matter.Composite.move
- Matter.Composite.rebase
- Matter.World.remove
- Matter.Composite.removeBody
- Matter.Composite.removeBodyAt
- Matter.Composite.removeComposite
- Matter.Composite.removeCompositeAt
- Matter.Composite.removeConstraint
- Matter.Composite.removeConstraintAt
- Matter.Composite.rotate
- Matter.Composite.scale
- Matter.Composite.setModified
- Matter.Composite.translate
- Item Index
- Properties
- Events
- Methods
Matter.World
Extends Composite
Defined in: src/body/World.js:1
The Matter.World
module contains methods for creating and manipulating the world composite. A Matter.World
is a Matter.Composite
body, which is a collection of Matter.Body
, Matter.Constraint
and other Matter.Composite
. A Matter.World
has a few additional properties including gravity
and bounds
. It is important to use the functions in the Matter.Composite
module to modify the world composite, rather than directly modifying its properties. There are also a few methods here that alias those in Matter.Composite
for easier readability.
See the included usage examples.
Methods
Matter.World.add
(world, object)
Inherited from Composite but overwritten in
An alias for Composite.add
Parameters
world
World
object
Object
Returns
CompositeThe original world with the objects added
Matter.World.addBody
(world, body)
→ World
Inherited from Composite but overwritten in
An alias for Composite.addBody
Parameters
world
World
body
Body
Returns
WorldThe original world with the body added
Matter.World.addComposite
(world, composite)
→ World
Inherited from Composite but overwritten in
An alias for Composite.addComposite
Parameters
world
World
composite
Composite
Returns
WorldThe original world with the objects from composite added
Matter.World.addConstraint
(world, constraint)
→ World
Inherited from Composite but overwritten in
An alias for Composite.addConstraint
Parameters
world
World
constraint
Constraint
Returns
WorldThe original world with the constraint added
Matter.Composite.allBodies
(composite)
→ Body[]
Inherited from Composite:
Returns all bodies in the given composite, including all bodies in its children, recursively.
Parameters
composite
Composite
Returns
Body[]All the bodies
Matter.Composite.allComposites
(composite)
Inherited from Composite:
Returns all composites in the given composite, including all composites in its children, recursively.
Parameters
composite
Composite
Returns
Composite[]All the composites
Matter.Composite.allConstraints
(composite)
Inherited from Composite:
Returns all constraints in the given composite, including all constraints in its children, recursively.
Parameters
composite
Composite
Returns
Constraint[]All the constraints
Matter.Composite.bounds
(composite)
→ Bounds
Inherited from Composite:
Returns the union of the bounds of all of the composite's bodies.
Parameters
composite
Composite
The composite.
Returns
BoundsThe composite bounds.
Matter.World.clear
(world, keepStatic)
Inherited from Composite but overwritten in
An alias for Composite.clear
Parameters
world
World
keepStatic
Boolean
Matter.World.create
(options)
→ World
Inherited from Composite but overwritten in
Creates a new world composite. The options parameter is an object that specifies any properties you wish to override the defaults. See the properties section below for detailed information on what you can pass via the options
object.
Parameters
options
Object
Returns
WorldA new world
Matter.Composite.get
(composite, id, type)
→ Object
Inherited from Composite:
Searches the composite recursively for an object matching the type and id supplied, null if not found.
Parameters
composite
Composite
id
Number
type
String
Returns
ObjectThe requested object, if found
Matter.Composite.move
(compositeA, objects, compositeB)
Inherited from Composite:
Moves the given object(s) from compositeA to compositeB (equal to a remove followed by an add).
Parameters
compositeA
CompositeA
objects
Object[]
compositeB
CompositeB
Returns
CompositeReturns compositeA
Matter.Composite.rebase
(composite)
Inherited from Composite:
Assigns new ids for all objects in the composite, recursively.
Parameters
composite
Composite
Returns
CompositeReturns composite
Matter.World.remove
(world, object, [deep=false])
Inherited from Composite but overwritten in
An alias for Composite.remove
Parameters
world
World
object
Object
[deep=false]
Booleanoptional
Returns
CompositeThe original world with the objects removed
Matter.Composite.removeBody
(composite, body, [deep=false])
→ Compositeprivate
Inherited from Composite:
Removes a body from the given composite, and optionally searching its children recursively.
Parameters
composite
Composite
body
Body
[deep=false]
Booleanoptional
Returns
CompositeThe original composite with the body removed
Matter.Composite.removeBodyAt
(composite, position)
→ Compositeprivate
Inherited from Composite:
Removes a body from the given composite.
Parameters
composite
Composite
position
Number
Returns
CompositeThe original composite with the body removed
Matter.Composite.removeComposite
(compositeA, compositeB, [deep=false])
→ Compositeprivate
Inherited from Composite:
Removes a composite from the given composite, and optionally searching its children recursively.
Parameters
compositeA
Composite
compositeB
Composite
[deep=false]
Booleanoptional
Returns
CompositeThe original compositeA with the composite removed
Matter.Composite.removeCompositeAt
(composite, position)
→ Compositeprivate
Inherited from Composite:
Removes a composite from the given composite.
Parameters
composite
Composite
position
Number
Returns
CompositeThe original composite with the composite removed
Matter.Composite.removeConstraint
(composite, constraint, [deep=false])
→ Compositeprivate
Inherited from Composite:
Removes a constraint from the given composite, and optionally searching its children recursively.
Parameters
composite
Composite
constraint
Constraint
[deep=false]
Booleanoptional
Returns
CompositeThe original composite with the constraint removed
Matter.Composite.removeConstraintAt
(composite, position)
→ Compositeprivate
Inherited from Composite:
Removes a body from the given composite.
Parameters
composite
Composite
position
Number
Returns
CompositeThe original composite with the constraint removed
Matter.Composite.rotate
(composite, rotation, point, [recursive=true])
Inherited from Composite:
Rotates all children in the composite by a given angle about the given point, without imparting any angular velocity.
Parameters
composite
Composite
rotation
Number
point
Vector
[recursive=true]
Booloptional
Matter.Composite.scale
(composite, scaleX, scaleY, point, [recursive=true])
Inherited from Composite:
Scales all children in the composite, including updating physical properties (mass, area, axes, inertia), from a world-space point.
Parameters
composite
Composite
scaleX
Number
scaleY
Number
point
Vector
[recursive=true]
Booloptional
Matter.Composite.setModified
(composite, isModified, [updateParents=false], [updateChildren=false])
Inherited from Composite:
Sets the composite's isModified
flag. If updateParents
is true, all parents will be set (default: false). If updateChildren
is true, all children will be set (default: false).
Parameters
composite
Composite
isModified
Boolean
[updateParents=false]
Booleanoptional
[updateChildren=false]
Booleanoptional
Matter.Composite.translate
(composite, translation, [recursive=true])
Inherited from Composite:
Translates all children in the composite by a given vector relative to their current positions, without imparting any velocity.
Parameters
composite
Composite
translation
Vector
[recursive=true]
Booloptional
Item Index
Methods
- add
- addBody
- addComposite
- addConstraint
- allBodies
- allComposites
- allConstraints
- bounds
- clear
- create
- get
- move
- rebase
- remove
- removeBody
- removeBodyAt
- removeComposite
- removeCompositeAt
- removeConstraint
- removeConstraintAt
- rotate
- scale
- setModified
- translate
Properties
The following properties are specified for objects created by <span class="prefix">Matter.</span>.create
and for objects passed to it via the options
argument.
- bodies
- bounds
- composites
- constraints
- gravity
- gravity.scale
- gravity.x
- gravity.y
- id
- isModified
- label
- parent
- plugin
- type
Events
Properties
The following properties are specified for objects created by Matter.World.create
and for objects passed to it via the options
argument.
Composite.bodies
Inherited from Composite:
An array of Body
that are direct children of this composite. To add or remove bodies you should use Composite.add
and Composite.remove
methods rather than directly modifying this property. If you wish to recursively find all descendants, you should use the Composite.allBodies
method.
Default: []
World.bounds
A Bounds
object that defines the world bounds for collision detection.
Default: { min: { x: -Infinity, y: -Infinity }, max: { x: Infinity, y: Infinity } }
Composite.composites
Inherited from Composite:
An array of Composite
that are direct children of this composite. To add or remove composites you should use Composite.add
and Composite.remove
methods rather than directly modifying this property. If you wish to recursively find all descendants, you should use the Composite.allComposites
method.
Default: []
Composite.constraints
Inherited from Composite:
An array of Constraint
that are direct children of this composite. To add or remove constraints you should use Composite.add
and Composite.remove
methods rather than directly modifying this property. If you wish to recursively find all descendants, you should use the Composite.allConstraints
method.
Default: []
World.gravity
The gravity to apply on the world.
World.gravity.scale
The gravity scale factor.
Default: 0.001
World.gravity.x
The gravity x component.
Default: 0
World.gravity.y
The gravity y component.
Default: 1
Composite.id
Inherited from Composite:
An integer Number
uniquely identifying number generated in Composite.create
by Common.nextId
.
Composite.isModified
Inherited from Composite:
A flag that specifies whether the composite has been modified during the current step. Most Matter.Composite
methods will automatically set this flag to true
to inform the engine of changes to be handled. If you need to change it manually, you should use the Composite.setModified
method.
Default: false
Composite.label
Inherited from Composite:
An arbitrary String
name to help the user identify and manage composites.
Default: "Composite"
Composite.parent
Inherited from Composite:
The Composite
that is the parent of this composite. It is automatically managed by the Matter.Composite
methods.
Default: null
Composite.plugin
Inherited from Composite:
An object reserved for storing plugin-specific properties.
Composite.type
Inherited from Composite:
A String
denoting the type of object.
Default: "composite"
Events
The following events are emitted by objects created by <span class="prefix">Matter.</span>World.create
to objects that have subscribed using Matter.Events.on
.
Events.on(Composite, "afterAdd", callback)
Inherited from Composite:
Fired when a call to Composite.add
is made, after objects have been added.
Event Payload:
event
Object
An event object
object
The object(s) that have been added (may be a single body, constraint, composite or a mixed array of these)
source
The source object of the event
name
The name of the event
Events.on(Composite, "afterRemove", callback)
Inherited from Composite:
Fired when a call to Composite.remove
is made, after objects have been removed.
Event Payload:
event
Object
An event object
object
The object(s) that have been removed (may be a single body, constraint, composite or a mixed array of these)
source
The source object of the event
name
The name of the event
Events.on(Composite, "beforeAdd", callback)
Inherited from Composite:
Fired when a call to Composite.add
is made, before objects have been added.
Event Payload:
event
Object
An event object
object
The object(s) to be added (may be a single body, constraint, composite or a mixed array of these)
source
The source object of the event
name
The name of the event
Events.on(Composite, "beforeRemove", callback)
Inherited from Composite:
Fired when a call to Composite.remove
is made, before objects have been removed.
Event Payload:
event
Object
An event object
object
The object(s) to be removed (may be a single body, constraint, composite or a mixed array of these)
source
The source object of the event
name
The name of the event