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 19)

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 45)

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 54)

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 36)

Methods


angularVelocity(body, velocity)

Instantly sets the angular velocity of the given body. Position, angle, force etc. are unchanged.

See also force.

Parameters:
Name Type Description
body MatterJS.Body

The Matter Body to set the velocity on.

velocity number

The angular velocity to set.

Since: 3.18.0
Source: src/physics/matter-js/Factory.js (Line 642)
Returns:

The Matter body.

Type
MatterJS.Body

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 346)
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 284)
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 Argument 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 <optional>

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

maxSides number <optional>

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 111)
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 <optional>

[description]

stiffness number <optional>
1

[description]

options object <optional>
{}

[description]

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

A Matter JS Constraint.

Type
MatterJS.Constraint

destroy()

Destroys this Factory.

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

force(body, position, force)

Applies a force to a body from a given world-space position, including resulting torque.

Parameters:
Name Type Description
body MatterJS.Body

The Matter Body to set the force on.

position Phaser.Types.Math.Vector2Like

The world position to apply the force from. An object with public x and y components.

force Phaser.Types.Math.Vector2Like

The force to set. An object with public x and y components.

Since: 3.18.0
Source: src/physics/matter-js/Factory.js (Line 662)
Returns:

The Matter body.

Type
MatterJS.Body

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 Argument Default Description
x number

The X coordinate of the center of the Body.

y number

The Y coordinate of the center of the Body.

vertexSets string | array

[description]

options object <optional>

[description]

flagInternal boolean <optional>
false

Flag internal edges (coincident part edges)

removeCollinear number <optional>
0.01

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

minimumArea number <optional>
10

During decomposition discard parts that have an area less than this.

Since: 3.0.0
Source: src/physics/matter-js/Factory.js (Line 157)
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 | MatterJS.Body

A Matter Body configuration object, or an instance of a Matter Body.

Since: 3.3.0
Source: src/physics/matter-js/Factory.js (Line 606)
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 541)
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 188)
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 397)
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 304)
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 500)
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 323)
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 515)
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 134)
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 258)
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 64)
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 369)
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 416)
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 582)
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 232)
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 564)
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 87)
Returns:

A Matter JS Body.

Type
MatterJS.Body

velocity(body, velocity)

Instantly sets the linear velocity of the given body. Position, angle, force etc. are unchanged.

See also force.

Parameters:
Name Type Description
body MatterJS.Body

The Matter Body to set the velocity on.

velocity Phaser.Types.Math.Vector2Like

The velocity to set. An object with public x and y components.

Since: 3.18.0
Source: src/physics/matter-js/Factory.js (Line 622)
Returns:

The Matter 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 471)
Returns:

A Matter JS Constraint.

Type
MatterJS.Constraint