Class: Factory

Phaser.Physics.Matter. Factory

The Matter Factory can create different types of bodies and them to a physics world.


new Factory(world)

Parameters:
Name Type Description
world Phaser.Physics.Matter.World

The Matter World which this Factory adds to.

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 17)

Members


scene :Phaser.Scene

The Scene which this Factory's Matter World belongs to.

Type:
Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 43)

sys :Phaser.Scenes.Systems

A reference to the Scene.Systems this Matter Physics instance belongs to.

Type:
Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 52)

world :Phaser.Physics.Matter.World

The Matter World which this Factory adds to.

Type:
Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 34)

Methods


car(x, y, width, height, wheelSize)

Creates a composite with simple car setup of bodies and constraints.

Parameters:
Name Type Description
x number

[description]

y number

[description]

width number

[description]

height number

[description]

wheelSize number

[description]

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 339)
Returns:

A new composite car body.

Type
MatterJS.Composite

chain(composite, xOffsetA, yOffsetA, xOffsetB, yOffsetB, options)

Chains all bodies in the given composite together using constraints.

Parameters:
Name Type Description
composite MatterJS.Composite

[description]

xOffsetA number

[description]

yOffsetA number

[description]

xOffsetB number

[description]

yOffsetB number

[description]

options object

[description]

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 277)
Returns:

A new composite containing objects chained together with constraints.

Type
MatterJS.Composite

circle(x, y, radius, options, maxSides)

Creates a new rigid circular Body and adds it to the World.

Parameters:
Name Type Description
x number

The X coordinate of the center of the Body.

y number

The Y coordinate of the center of the Body.

radius number

The radius of the circle.

options object

An object of properties to set on the Body. You can also specify a chamfer property to automatically adjust the body.

maxSides number

The maximum amount of sides to use for the polygon which will approximate this circle.

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 109)
Returns:

A Matter JS Body.

Type
MatterJS.Body

constraint(bodyA, bodyB, length [, stiffness] [, options])

[description]

Parameters:
Name Type Argument Default Description
bodyA MatterJS.Body

[description]

bodyB MatterJS.Body

[description]

length number

[description]

stiffness number <optional>
1

[description]

options object <optional>
{}

[description]

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 428)
Returns:

A Matter JS Constraint.

Type
MatterJS.Constraint

destroy()

Destroys this Factory.

Since: 3.5.0
Source: src/physics/matter-js/Factory.js (Line 610)

fromVertices(x, y, vertexSets, options, flagInternal, removeCollinear, minimumArea)

Creates a body using the supplied vertices (or an array containing multiple sets of vertices) and adds it to the World. If the vertices are convex, they will pass through as supplied. Otherwise, if the vertices are concave, they will be decomposed. Note that this process is not guaranteed to support complex sets of vertices, e.g. ones with holes.

Parameters:
Name Type Description
x number

The X coordinate of the center of the Body.

y number

The Y coordinate of the center of the Body.

vertexSets array

[description]

options object

[description]

flagInternal boolean

Flag internal edges (coincident part edges)

removeCollinear boolean

Whether Matter.js will discard collinear edges (to improve performance).

minimumArea number

During decomposition discard parts that have an area less than this

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 155)
Returns:

A Matter JS Body.

Type
MatterJS.Body

gameObject(gameObject, options)

[description]

Parameters:
Name Type Description
gameObject Phaser.GameObjects.GameObject

The Game Object to inject the Matter Body in to.

options object

[description]

Since: 3.3.0
Source: src/physics/matter-js/Factory.js (Line 594)
Returns:

The Game Object that had the Matter Body injected into it.

Type
Phaser.GameObjects.GameObject

image(x, y, key [, frame] [, options])

[description]

Parameters:
Name Type Argument Default Description
x number

The horizontal position of this Game Object in the world.

y number

The vertical position of this Game Object in the world.

key string

The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.

frame string | integer <optional>

An optional frame from the Texture this Game Object is rendering with. Set to null to skip this value.

options object <optional>
{}

[description]

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 529)
Returns:

[description]

Type
Phaser.Physics.Matter.Image

imageStack(key, frame, x, y, columns, rows [, columnGap] [, rowGap] [, options])

Create a new composite containing Matter Image objects created in a grid arrangement. This function uses the body bounds to prevent overlaps.

Parameters:
Name Type Argument Default Description
key string

The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.

frame string | integer

An optional frame from the Texture this Game Object is rendering with. Set to null to skip this value.

x number

The horizontal position of this composite in the world.

y number

The vertical position of this composite in the world.

columns number

The number of columns in the grid.

rows number

The number of rows in the grid.

columnGap number <optional>
0

The distance between each column.

rowGap number <optional>
0

The distance between each row.

options object <optional>

[description]

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 181)
Returns:

A Matter JS Composite Stack.

Type
MatterJS.Composite

joint(bodyA, bodyB, length [, stiffness] [, options])

[description]

Parameters:
Name Type Argument Default Description
bodyA MatterJS.Body

[description]

bodyB MatterJS.Body

[description]

length number

[description]

stiffness number <optional>
1

[description]

options object <optional>
{}

[description]

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 390)
Returns:

A Matter JS Constraint.

Type
MatterJS.Constraint

mesh(composite, columns, rows, crossBrace, options)

Connects bodies in the composite with constraints in a grid pattern, with optional cross braces.

Parameters:
Name Type Description
composite MatterJS.Composite

[description]

columns number

[description]

rows number

[description]

crossBrace boolean

[description]

options object

[description]

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 297)
Returns:

The composite containing objects meshed together with constraints.

Type
MatterJS.Composite

mouseSpring(options)

[description]

Parameters:
Name Type Description
options object

[description]

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 488)
Returns:

A Matter JS Constraint.

Type
MatterJS.Constraint

newtonsCradle(x, y, number, size, length)

Creates a composite with a Newton's Cradle setup of bodies and constraints.

Parameters:
Name Type Description
x number

[description]

y number

[description]

number number

[description]

size number

[description]

length number

[description]

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 316)
Returns:

A new composite newtonsCradle body.

Type
MatterJS.Composite

pointerConstraint(options)

[description]

Parameters:
Name Type Description
options object

[description]

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 503)
Returns:

A Matter JS Constraint.

Type
MatterJS.Constraint

polygon(x, y, sides, radius, options)

Creates a new rigid polygonal Body and adds it to the World.

Parameters:
Name Type Description
x number

The X coordinate of the center of the Body.

y number

The Y coordinate of the center of the Body.

sides number

The number of sides the polygon will have.

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.

options object

An object of properties to set on the Body. You can also specify a chamfer property to automatically adjust the body.

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 132)
Returns:

A Matter JS Body.

Type
MatterJS.Body

pyramid(x, y, columns, rows, columnGap, rowGap, callback)

Create a new composite containing bodies created in the callback in a pyramid arrangement. This function uses the body bounds to prevent overlaps.

Parameters:
Name Type Description
x number

The horizontal position of this composite in the world.

y number

The vertical position of this composite in the world.

columns number

The number of columns in the pyramid.

rows number

The number of rows in the pyramid.

columnGap number

The distance between each column.

rowGap number

The distance between each row.

callback function

The callback function to be invoked.

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 251)
Returns:

A Matter JS Composite pyramid.

Type
MatterJS.Composite

rectangle(x, y, width, height, options)

Creates a new rigid rectangular Body and adds it to the World.

Parameters:
Name Type Description
x number

The X coordinate of the center of the Body.

y number

The Y coordinate of the center of the Body.

width number

The width of the Body.

height number

The height of the Body.

options object

An object of properties to set on the Body. You can also specify a chamfer property to automatically adjust the body.

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 62)
Returns:

A Matter JS Body.

Type
MatterJS.Body

softBody(x, y, columns, rows, columnGap, rowGap, crossBrace, particleRadius, particleOptions, constraintOptions)

Creates a simple soft body like object.

Parameters:
Name Type Description
x number

The horizontal position of this composite in the world.

y number

The vertical position of this composite in the world.

columns number

The number of columns in the Composite.

rows number

The number of rows in the Composite.

columnGap number

The distance between each column.

rowGap number

The distance between each row.

crossBrace boolean

[description]

particleRadius number

The radius of this circlular composite.

particleOptions object

[description]

constraintOptions object

[description]

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 362)
Returns:

A new composite simple soft body.

Type
MatterJS.Composite

spring(bodyA, bodyB, length [, stiffness] [, options])

[description]

Parameters:
Name Type Argument Default Description
bodyA MatterJS.Body

The first possible Body that this constraint is attached to.

bodyB MatterJS.Body

The second possible Body that this constraint is attached to.

length number

A Number that specifies the target resting length of the constraint. It is calculated automatically in Constraint.create from initial positions of the constraint.bodyA and constraint.bodyB

stiffness number <optional>
1

A Number that specifies the stiffness of the constraint, i.e. the rate at which it returns to its resting constraint.length. A value of 1 means the constraint should be very stiff. A value of 0.2 means the constraint acts as a soft spring.

options object <optional>
{}

[description]

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 409)
Returns:

A Matter JS Constraint.

Type
MatterJS.Constraint

sprite(x, y, key [, frame] [, options])

[description]

Parameters:
Name Type Argument Default Description
x number

The horizontal position of this Game Object in the world.

y number

The vertical position of this Game Object in the world.

key string

The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.

frame string | integer <optional>

An optional frame from the Texture this Game Object is rendering with. Set to null to skip this value.

options object <optional>
{}

[description]

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 570)
Returns:

[description]

Type
Phaser.Physics.Matter.Sprite

stack(x, y, columns, rows, columnGap, rowGap, callback)

Create a new composite containing bodies created in the callback in a grid arrangement. This function uses the body bounds to prevent overlaps.

Parameters:
Name Type Description
x number

The horizontal position of this composite in the world.

y number

The vertical position of this composite in the world.

columns number

The number of columns in the grid.

rows number

The number of rows in the grid.

columnGap number

The distance between each column.

rowGap number

The distance between each row.

callback function

The callback that creates the stack.

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 225)
Returns:

A new composite containing objects created in the callback.

Type
MatterJS.Composite

tileBody(tile, options)

[description]

Parameters:
Name Type Description
tile Phaser.Tilemaps.Tile

[description]

options object

[description]

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 552)
Returns:

[description]

Type
Phaser.Physics.Matter.TileBody

trapezoid(x, y, width, height, slope, options)

Creates a new rigid trapezoidal Body and adds it to the World.

Parameters:
Name Type Description
x number

The X coordinate of the center of the Body.

y number

The Y coordinate of the center of the Body.

width number

The width of the trapezoid of the Body.

height number

The height of the trapezoid of the 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.

options object

An object of properties to set on the Body. You can also specify a chamfer property to automatically adjust the body.

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 85)
Returns:

A Matter JS Body.

Type
MatterJS.Body

worldConstraint(bodyB, length [, stiffness] [, options])

[description]

Parameters:
Name Type Argument Default Description
bodyB MatterJS.Body

[description]

length number

[description]

stiffness number <optional>
1

[description]

options object <optional>
{}

[description]

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 459)
Returns:

A Matter JS Constraint.

Type
MatterJS.Constraint