Matter.MouseConstraint

Defined in: src/constraint/MouseConstraint.js:1

The Matter.MouseConstraint module contains methods for creating mouse constraints. Mouse constraints are used for allowing user interaction, providing the ability to move bodies via the mouse or touch.

See the included usage examples.

Methods

Matter.MouseConstraint._triggerEvents

(mouseConstraint)

private

Triggers mouse constraint events.

Parameters

@ src/constraint/MouseConstraint.js:133

Matter.MouseConstraint.create

(engine, options)

MouseConstraint

Creates a new mouse constraint. All properties have default values, and many are pre-calculated automatically based on other properties. See the properties section below for detailed information on what you can pass via the options object.

Parameters

Returns

MouseConstraintA new MouseConstraint

@ src/constraint/MouseConstraint.js:26

Matter.MouseConstraint.update

(mouseConstraint, bodies)

private

Updates the given mouse constraint.

Parameters

@ src/constraint/MouseConstraint.js:86

Item Index

Methods

Properties

The following properties are specified for objects created by <span class="prefix">Matter.</span>.create and for objects passed to it via the options argument.

Events

Properties

The following properties are specified for objects created by Matter.MouseConstraint.create and for objects passed to it via the options argument.

MouseConstraint.body

Body

The Body that is currently being moved by the user, or null if no body.

Default: null

@ src/constraint/MouseConstraint.js:237

MouseConstraint.collisionFilter

Object

An Object that specifies the collision filter properties. The collision filter allows the user to define which types of body this mouse constraint can interact with. See body.collisionFilter for more information.

@ src/constraint/MouseConstraint.js:252

MouseConstraint.constraint

Constraint

The Constraint object that is used to move the body during interaction.

@ src/constraint/MouseConstraint.js:245

MouseConstraint.mouse

Mouse

The Mouse instance in use. If not supplied in MouseConstraint.create, one will be created.

Default: mouse

@ src/constraint/MouseConstraint.js:229

MouseConstraint.type

String

A String denoting the type of object.

Default: "constraint"

@ src/constraint/MouseConstraint.js:220

Events

The following events are emitted by objects created by <span class="prefix">Matter.</span>MouseConstraint.create to objects that have subscribed using Matter.Events.on.

Events.on(MouseConstraint, "enddrag", callback)

Fired when the user ends dragging a body

Event Payload:

An event object

The engine's mouse instance

The body that has stopped being dragged

  • source

The source object of the event

  • name

The name of the event

@ src/constraint/MouseConstraint.js:203

Events.on(MouseConstraint, "mousedown", callback)

Fired when the mouse is down (or a touch has started) during the last step

Event Payload:

An event object

The engine's mouse instance

  • source

The source object of the event

  • name

The name of the event

@ src/constraint/MouseConstraint.js:172

Events.on(MouseConstraint, "mousemove", callback)

Fired when the mouse has moved (or a touch moves) during the last step

Event Payload:

An event object

The engine's mouse instance

  • source

The source object of the event

  • name

The name of the event

@ src/constraint/MouseConstraint.js:162

Events.on(MouseConstraint, "mouseup", callback)

Fired when the mouse is up (or a touch has ended) during the last step

Event Payload:

An event object

The engine's mouse instance

  • source

The source object of the event

  • name

The name of the event

@ src/constraint/MouseConstraint.js:182

Events.on(MouseConstraint, "startdrag", callback)

Fired when the user starts dragging a body

Event Payload:

An event object

The engine's mouse instance

The body being dragged

  • source

The source object of the event

  • name

The name of the event

@ src/constraint/MouseConstraint.js:192