Skip to main content
Version: Phaser v4.0.0

Phaser.Physics.Matter

Scope: static

Source: src/physics/matter-js/index.js#L7

Static functions

Static functions

Static functions

MatterGameObject

<static> MatterGameObject(world, gameObject, [options], [addToWorld])

Description:

A factory function that mixes all Matter.js physics components into any existing Phaser Game Object, including those you have extended or created yourself. This enables you to give any Game Object full Matter physics capabilities without requiring it to extend a specific class.

The following components are mixed directly onto the Game Object: Bounce, Collision, Force, Friction, Gravity, Mass, Sensor, SetBody, Sleep, Static, Transform, and Velocity. This means methods such as setVelocity, setFriction, and isSensor become available directly on the Game Object after this function is called.

If options is an existing Matter Body instance (i.e. its type property equals 'body'), that body is attached via setExistingBody. Otherwise, options is treated as a MatterBodyConfig and a new body is created via setBody, defaulting to a rectangle shape if no shape property is provided.

Parameters:

nametypeoptionaldefaultdescription
worldPhaser.Physics.Matter.WorldNoThe Matter world to add the body to.
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will have the Matter body applied to it.
optionsPhaser.Types.Physics.Matter.MatterBodyConfig | MatterJS.BodyYesA Matter Body configuration object, or an instance of a Matter Body.
addToWorldbooleanYestrueShould the newly created body be immediately added to the World?

Returns: Phaser.GameObjects.GameObject - The Game Object that was passed in, now enhanced with Matter physics components.

Source: src/physics/matter-js/MatterGameObject.js#L26
Since: 3.3.0