Show:
API

Matter.MouseConstraint

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

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

MouseConstraint

A new MouseConstraint

Matter.MouseConstraint.update

(mouseConstraint, bodies)
private

Updates the given mouse constraint.

Parameters

Properties / Options

The following properties if specified below are for objects created by Matter.MouseConstraint.create and may be passed to it as options.

MouseConstraint.body

Body

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

Default: null

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.

MouseConstraint.constraint

Constraint

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

MouseConstraint.mouse

Mouse

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

Default: mouse

MouseConstraint.type

String

A String denoting the type of object.

Default: "constraint"

Events

The following events are emitted by objects created by Matter.MouseConstraint.create and received by objects that have subscribed using Matter.Events.on.

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

Fired when the user ends dragging a body

Callback Parameters

  • event Object

    An event object

    • mouse Mouse

      The engine's mouse instance

    • body Body

      The body that has stopped being dragged

    • source

      The source object of the event

    • name

      The name of the event

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

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

Callback Parameters

  • event Object

    An event object

    • mouse Mouse

      The engine's mouse instance

    • source

      The source object of the event

    • name

      The name of the event

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

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

Callback Parameters

  • event Object

    An event object

    • mouse Mouse

      The engine's mouse instance

    • source

      The source object of the event

    • name

      The name of the event

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

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

Callback Parameters

  • event Object

    An event object

    • mouse Mouse

      The engine's mouse instance

    • source

      The source object of the event

    • name

      The name of the event

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

Fired when the user starts dragging a body

Callback Parameters

  • event Object

    An event object

    • mouse Mouse

      The engine's mouse instance

    • body Body

      The body being dragged

    • source

      The source object of the event

    • name

      The name of the event