phaser - v4.0.0-rc.4
    Preparing search index...

    Enables a Matter-enabled Game Object to set its Body. Should be used as a mixin and not directly.

    interface SetBody {
        setBody(
            config: string | MatterSetBodyConfig,
            options?: MatterBodyConfig,
        ): this;
        setCircle(radius: number, options?: MatterBodyConfig): this;
        setExistingBody(body: MatterJS.BodyType, addToWorld?: boolean): this;
        setPolygon(radius: number, sides: number, options?: MatterBodyConfig): this;
        setRectangle(
            width: number,
            height: number,
            options?: MatterBodyConfig,
        ): this;
        setTrapezoid(
            width: number,
            height: number,
            slope: number,
            options?: MatterBodyConfig,
        ): this;
    }

    Implemented by

    Index

    Methods

    • Set this Game Object to create and use a new Body based on the configuration object given.

      Calling this methods resets all previous properties you may have set on the body, including plugins, mass, friction, collision categories, etc. So be sure to re-apply these as needed.

      Parameters

      • config: string | MatterSetBodyConfig

        Either a string, such as circle, or a Matter Set Body Configuration object.

      • Optionaloptions: MatterBodyConfig

        An optional Body configuration object that is used to set initial Body properties on creation.

      Returns this

    • Set this Game Objects Matter physics body to be a circle shape.

      Calling this methods resets all previous properties you may have set on the body, including plugins, mass, friction, collision categories, etc. So be sure to re-apply these as needed.

      Parameters

      • radius: number

        The radius of the circle.

      • Optionaloptions: MatterBodyConfig

        An optional Body configuration object that is used to set initial Body properties on creation.

      Returns this

    • Set this Game Object to use the given existing Matter Body.

      The body is first removed from the world before being added to this Game Object.

      Parameters

      • body: MatterJS.BodyType

        The Body this Game Object should use.

      • OptionaladdToWorld: boolean

        Should the body be immediately added to the World? Default true.

      Returns this

    • Set this Game Objects Matter physics body to be a polygon shape.

      Calling this methods resets all previous properties you may have set on the body, including plugins, mass, friction, collision categories, etc. So be sure to re-apply these as needed.

      Parameters

      • radius: number

        The "radius" of the polygon, i.e. the distance from its center to any vertex. This is also the radius of its circumcircle.

      • sides: number

        The number of sides the polygon will have.

      • Optionaloptions: MatterBodyConfig

        An optional Body configuration object that is used to set initial Body properties on creation.

      Returns this

    • Set this Game Objects Matter physics body to be a rectangle shape.

      Calling this methods resets all previous properties you may have set on the body, including plugins, mass, friction, collision categories, etc. So be sure to re-apply these as needed.

      Parameters

      • width: number

        Width of the rectangle.

      • height: number

        Height of the rectangle.

      • Optionaloptions: MatterBodyConfig

        An optional Body configuration object that is used to set initial Body properties on creation.

      Returns this

    • Set this Game Objects Matter physics body to be a trapezoid shape.

      Calling this methods resets all previous properties you may have set on the body, including plugins, mass, friction, collision categories, etc. So be sure to re-apply these as needed.

      Parameters

      • width: number

        The width of the trapezoid Body.

      • height: number

        The height of the trapezoid Body.

      • slope: number

        The slope of the trapezoid. 0 creates a rectangle, while 1 creates a triangle. Positive values make the top side shorter, while negative values make the bottom side shorter.

      • Optionaloptions: MatterBodyConfig

        An optional Body configuration object that is used to set initial Body properties on creation.

      Returns this