Skip to main content
Version: Phaser v4.0.0

Phaser.Physics.Matter.PhysicsEditorParser

Scope: static

Source: src/physics/matter-js/PhysicsEditorParser.js#L15
Since: 3.10.0

Static functions

parseBody

<static> parseBody(x, y, config, [options])

Description:

Parses a body configuration exported by PhysicsEditor and creates a compound Matter.js body from it. Each fixture definition in the configuration is parsed and converted into a child body (either a circle or a convex polygon), and all child bodies are combined into a single compound body positioned at the given world coordinates. Additional Matter.js body properties can be supplied via the options argument and will be merged into the body configuration.

Parameters:

nametypeoptionaldescription
xnumberNoThe horizontal world location of the body.
ynumberNoThe vertical world location of the body.
configobjectNoThe body configuration and fixture (child body) definitions, as exported by PhysicsEditor.
optionsPhaser.Types.Physics.Matter.MatterBodyConfigYesAn optional Body configuration object that is used to set initial Body properties on creation.

Returns: MatterJS.BodyType - A compound Matter JS Body.

Source: src/physics/matter-js/PhysicsEditorParser.js#L29
Since: 3.10.0


parseFixture

<static> parseFixture(fixtureConfig)

Description:

Parses a single fixture entry from the "fixtures" list exported by PhysicsEditor. A fixture can describe either a circle (defined by a centre position and radius) or a set of convex polygon vertex lists. The appropriate Matter.js body or bodies are created and returned as an array so they can be combined into a compound body by the caller.

Parameters:

nametypeoptionaldescription
fixtureConfigobjectNoThe fixture object to parse.

Returns: Array.<MatterJS.BodyType> - - An array of Matter JS Bodies.

Source: src/physics/matter-js/PhysicsEditorParser.js#L79
Since: 3.10.0


parseVertices

<static> parseVertices(vertexSets, [options])

Description:

Parses one or more vertex sets exported by PhysicsEditor and creates a Matter.js body for each set. Before creating each body, the vertices are sorted into clockwise winding order and the body is positioned at the centroid of the vertex set. After all bodies are created, coincident edges between adjacent parts are flagged so that Matter.js can handle them correctly during collision detection.

Parameters:

nametypeoptionaldescription
vertexSetsarrayNoThe vertex lists to parse.
optionsPhaser.Types.Physics.Matter.MatterBodyConfigYesAn optional Body configuration object that is used to set initial Body properties on creation.

Returns: Array.<MatterJS.BodyType> - - An array of Matter JS Bodies.

Source: src/physics/matter-js/PhysicsEditorParser.js#L116
Since: 3.10.0