A composite is a collection of Matter.Body, Matter.Constraint and other Matter.Composite objects.

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.

Hierarchy

  • default

Constructors

Methods

  • Returns all bodies in the given composite, including all bodies in its children, recursively.

    Parameters

    Returns IBody[]

    All the bodies

    Method

    allBodies

  • Removes all bodies, constraints and composites from the given composite. Optionally clearing its children recursively.

    Parameters

    • composite: IComposite
    • keepStatic: boolean
    • deep: boolean = false

    Returns IComposite

    Method

    clear

  • Creates 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.

    Parameters

    • options: {
          bodies?: IBody[];
          cache?: { allBodies?: IBody[] | null | undefined; allConstraints?: IConstraint[] | null | undefined; allComposites?: IComposite[] | null | undefined; };
          composites?: IComposite[];
          constraints?: IConstraint[];
          events?: { beforeAdd?: Function[] | undefined; afterAdd?: Function[] | undefined; beforeRemove?: Function[] | undefined; afterRemove?: Function[] | undefined; };
          gravity?: { x?: number | undefined; y?: number | undefined; scale?: number | undefined; };
          id?: number;
          isModified?: boolean;
          label?: string;
          parent?: null | ({ id?: number | undefined; type?: "composite" | undefined; label?: string | undefined; isModified?: boolean | undefined; parent?: ... | null | undefined; bodies?: IBody[] | undefined; ... 5 more ...; gravity?: { ...; } | undefined; });
          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; });
          type?: "composite";
      } = {}
      • 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.

        Default

        []
        
      • 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.

        Default

        []
        
      • 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.

        Default

        []
        
      • 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?: number

        An integer Number uniquely identifying number generated in Composite.create by Common.nextId.

      • Optional isModified?: boolean

        A 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.

        Default

        false
        
      • Optional label?: string

        An arbitrary String name to help the user identify and manage composites.

        Default

        "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.

        Default

        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.

        Default

        {}
        
      • Optional type?: "composite"

        A String denoting the type of object.

    Returns IComposite

    A new composite

    Method

    create

  • Removes a body from the given composite, and optionally searching its children recursively.

    Parameters

    Returns IComposite

    The original composite with the body removed

    Method

    removeBody

  • Removes a composite from the given composite, and optionally searching its children recursively.

    Parameters

    Returns IComposite

    The original compositeA with the composite removed

    Method

    removeComposite

  • Removes a composite from the given composite.

    Parameters

    Returns IComposite

    The original composite with the composite removed

    Method

    removeCompositeAt

  • Removes a constraint from the given composite, and optionally searching its children recursively.

    Parameters

    Returns IComposite

    The original composite with the constraint removed

    Method

    removeConstraint

  • Private

    Removes a body from the given composite.

    Parameters

    Returns IComposite

    The original composite with the constraint removed

    Method

    removeConstraintAt

  • Rotates all children in the composite by a given angle about the given point, without imparting any angular velocity.

    Parameters

    Returns IComposite

    Method

    rotate

  • Scales all children in the composite, including updating physical properties (mass, area, axes, inertia), from a world-space point.

    Parameters

    • composite: IComposite
    • scaleX: number
    • scaleY: number
    • point: IVector
    • recursive: boolean = true

    Returns IComposite

    Method

    scale

  • 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: IComposite
    • isModified: boolean
    • updateParents: boolean = false
    • updateChildren: boolean = false

    Returns void

    Method

    setModified

  • Translates all children in the composite by a given vector relative to their current positions, without imparting any velocity.

    Parameters

    Returns IComposite

    Method

    translate

Generated using TypeDoc