A Pointer Constraint is a special type of constraint that allows you to click
and drag bodies in a Matter World. It monitors the active Pointers in a Scene,
and when one is pressed down it checks to see if that hit any part of any active
body in the world. If it did, and the body has input enabled, it will begin to
drag it until either released, or you stop it via the stopDrag
method.
You can adjust the stiffness, length and other properties of the constraint via
the options
object on creation.
new PointerConstraint(scene, world, [options])
name | type | arguments | description |
---|---|---|---|
scene | Phaser.Scene |
A reference to the Scene to which this Pointer Constraint belongs. |
|
world | Phaser.Physics.Matter.World |
A reference to the Matter World instance to which this Constraint belongs. |
|
options | object | <optional> |
A Constraint configuration object. |
Is this Constraint active or not?
An active constraint will be processed each update. An inactive one will be skipped. Use this to toggle a Pointer Constraint on and off.
The body that is currently being dragged, if any.
The Camera the Pointer was interacting with when the input down event was processed.
The native Matter Constraint that is used to attach to bodies.
The part of the body that was clicked on to start the drag.
A reference to the Input Pointer that activated this Constraint.
This is set in the onDown
handler.
A reference to the Scene to which this Pointer Constraint belongs. This is the same Scene as the Matter World instance.
A reference to the Matter World instance to which this Constraint belongs.
Destroys this Pointer Constraint instance and all of its references.
Scans all active bodies in the current Matter World to see if any of them are hit by the Pointer. The first one found to hit is set as the active contraint body.
true
if a body was found and set, otherwise false
.
Scans the current body to determine if a part of it was clicked on.
If a part is found the body is set as the constraint.bodyB
property,
as well as the body
property of this class. The part is also set.
name | type | description |
---|---|---|
body | MatterJS.BodyType |
The Matter Body to check. |
position | Phaser.Math.Vector2 |
A translated hit test position. |
true
if a part of the body was hit, otherwise false
.
A Pointer has been pressed down onto the Scene.
If this Constraint doesn't have an active Pointer then a hit test is set to
run against all active bodies in the world during the next call to update
.
If a body is found, it is bound to this constraint and the drag begins.
name | type | description |
---|---|---|
pointer | Phaser.Input.Pointer |
A reference to the Pointer that was pressed. |
A Pointer has been released from the Scene. If it was the one this constraint was using, it's cleared.
name | type | description |
---|---|---|
pointer | Phaser.Input.Pointer |
A reference to the Pointer that was pressed. |
Stops the Pointer Constraint from dragging the body any further.
This is called automatically if the Pointer is released while actively dragging a body. Or, you can call it manually to release a body from a constraint without having to first release the pointer.
Internal update handler. Called in the Matter BEFORE_UPDATE step.