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
Triggers mouse constraint events.
Parameters
-
mouseConstraint
Mouse
Matter.MouseConstraint.create
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.
Returns
A new MouseConstraint
Matter.MouseConstraint.update
Updates the given mouse constraint.
Parameters
-
mouseConstraint
MouseConstraint -
bodies
Body[]
Properties / Options
The following properties if specified below are for objects created by Matter.MouseConstraint.create
and may be passed to it as options
.
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.
The Mouse
instance in use. If not supplied in MouseConstraint.create
, one will be created.
Default: mouse
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
Events.on(MouseConstraint, "mousedown
", callback)
Fired when the mouse is down (or a touch has started) during the last step
Callback Parameters
Events.on(MouseConstraint, "mousemove
", callback)
Fired when the mouse has moved (or a touch moves) during the last step
Callback Parameters
Events.on(MouseConstraint, "mouseup
", callback)
Fired when the mouse is up (or a touch has ended) during the last step
Callback Parameters
Events.on(MouseConstraint, "startdrag
", callback)
Fired when the user starts dragging a body