Phaser.Physics.Matter
Scope: static
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:
| name | type | optional | default | description |
|---|---|---|---|---|
| world | Phaser.Physics.Matter.World | No | The Matter world to add the body to. | |
| gameObject | Phaser.GameObjects.GameObject | No | The Game Object that will have the Matter body applied to it. | |
| options | Phaser.Types.Physics.Matter.MatterBodyConfig | MatterJS.Body | Yes | A Matter Body configuration object, or an instance of a Matter Body. | |
| addToWorld | boolean | Yes | true | Should 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