Static addGeneric single or multi-add function. Adds a single or an array of body(s), constraint(s) or composite(s) to the given composite.
Triggers beforeAdd and afterAdd events on the composite.
A single or an array of body(s), constraint(s) or composite(s)
The original composite with the objects added
add
Static addAdds a body to the given composite.
The original composite with the body added
addBody
Static addAdds a composite to the given composite.
The original compositeA with the objects from compositeB added
addComposite
Static addAdds a constraint to the given composite.
The original composite with the constraint added
addConstraint
Static allReturns all bodies in the given composite, including all bodies in its children, recursively.
All the bodies
allBodies
Static allReturns all composites in the given composite, including all composites in its children, recursively.
All the composites
allComposites
Static allReturns all constraints in the given composite, including all constraints in its children, recursively.
All the constraints
allConstraints
Static boundsReturns the union of the bounds of all of the composite's bodies.
The composite.
The composite bounds.
bounds
Static clearRemoves all bodies, constraints and composites from the given composite. Optionally clearing its children recursively.
clear
Static createCreates a new composite. The options parameter is an object that specifies any properties you wish to override the defaults.
See the properites section below for detailed information on what you can pass via the options object.
Optional bodies?: IBody[]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.
[]
Optional cache?: { allBodies?: IBody[] | null | undefined; allConstraints?: IConstraint[] | null | undefined; allComposites?: IComposite[] | null | undefined; }An object used for storing cached results for performance reasons. This is used internally only and is automatically managed.
Optional composites?: IComposite[]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.
[]
Optional constraints?: IConstraint[]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.
[]
Optional events?: { beforeAdd?: Function[] | undefined; afterAdd?: Function[] | undefined; beforeRemove?: Function[] | undefined; afterRemove?: Function[] | undefined; }Optional gravity?: { x?: number | undefined; y?: number | undefined; scale?: number | undefined; }Optional id?: numberAn integer Number uniquely identifying number generated in Composite.create by Common.nextId.
Optional isA flag that specifies whether the composite has been modified during the current step. This is automatically managed when bodies, constraints or composites are added or removed.
false
Optional label?: stringAn arbitrary String name to help the user identify and manage composites.
"Composite"
Optional parent?: null | ({ id?: number | undefined; type?: "composite" | undefined; label?: string | undefined; isModified?: boolean | undefined; parent?: ... | null | undefined; bodies?: IBody[] | undefined; ... 5 more ...; gravity?: { ...; } | undefined; })The Composite that is the parent of this composite. It is automatically managed by the Matter.Composite methods.
null
Optional plugin?: ({}) | ({ name?: string | undefined; version?: string | undefined; for?: string | undefined; uses?: string[] | undefined; install?: { apply?: {} | undefined; call?: {} | undefined; bind?: {} | undefined; ... 6 more ...; [Symbol.hasInstance]?: {} | undefined; } | undefined; _warned?: boolean | undefined; })An object reserved for storing plugin-specific properties.
{}
Optional type?: "composite"A String denoting the type of object.
A new composite
create
Static getSearches the composite recursively for an object matching the type and id supplied, null if not found.
The requested object, if found
get
Static moveMoves the given object(s) from compositeA to compositeB (equal to a remove followed by an add).
Returns compositeA
move
Static rebaseAssigns new ids for all objects in the composite, recursively.
Returns composite
rebase
Static removeGeneric remove function. Removes one or many body(s), constraint(s) or a composite(s) to the given composite.
Optionally searching its children recursively.
Triggers beforeRemove and afterRemove events on the composite.
The original composite with the objects removed
remove
Static Protected removeRemoves a body from the given composite, and optionally searching its children recursively.
The original composite with the body removed
removeBody
Static Protected removeRemoves a body from the given composite.
The original composite with the body removed
removeBodyAt
Static Protected removeRemoves a composite from the given composite, and optionally searching its children recursively.
The original compositeA with the composite removed
removeComposite
Static Protected removeRemoves a composite from the given composite.
The original composite with the composite removed
removeCompositeAt
Static Protected removeRemoves a constraint from the given composite, and optionally searching its children recursively.
The original composite with the constraint removed
removeConstraint
Static Private removePrivate
Removes a body from the given composite.
The original composite with the constraint removed
removeConstraintAt
Static rotateRotates all children in the composite by a given angle about the given point, without imparting any angular velocity.
rotate
Static scaleScales all children in the composite, including updating physical properties (mass, area, axes, inertia), from a world-space point.
scale
Static setSets 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).
setModified
Static translateTranslates all children in the composite by a given vector relative to their current positions, without imparting any velocity.
translate
Generated using TypeDoc
A composite is a collection of
Matter.Body,Matter.Constraintand otherMatter.Compositeobjects.They are a container that can represent complex objects made of multiple parts, even if they are not physically connected. A composite could contain anything from a single body all the way up to a whole world.
When making any changes to composites, use the included functions rather than changing their properties directly.
See the included usage examples.