Class: PointerConstraint

Phaser.Physics.Matter. PointerConstraint

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])

Parameters:
Name Type Argument 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.

Since: 3.0.0
Source: src/physics/matter-js/PointerConstraint.js (Line 19)

Members


active :boolean

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.

Type:
  • boolean
Since: 3.0.0
Default Value:
  • true
Source: src/physics/matter-js/PointerConstraint.js (Line 103)

<nullable> body :MatterJS.Body

The body that is currently being dragged, if any.

Type:
Since: 3.16.2
Source: src/physics/matter-js/PointerConstraint.js (Line 125)

camera :Phaser.Cameras.Scene2D.Camera

The Camera the Pointer was interacting with when the input down event was processed.

Type:
Since: 3.0.0
Source: src/physics/matter-js/PointerConstraint.js (Line 82)

constraint :object

The native Matter Constraint that is used to attach to bodies.

Type:
  • object
Since: 3.0.0
Source: src/physics/matter-js/PointerConstraint.js (Line 143)

<nullable> part :MatterJS.Body

The part of the body that was clicked on to start the drag.

Type:
Since: 3.16.2
Source: src/physics/matter-js/PointerConstraint.js (Line 134)

pointer :Phaser.Input.Pointer

A reference to the Input Pointer that activated this Constraint. This is set in the onDown handler.

Type:
Since: 3.0.0
Default Value:
  • null
Source: src/physics/matter-js/PointerConstraint.js (Line 92)

position :Phaser.Math.Vector2

The internal transformed position.

Type:
Since: 3.0.0
Source: src/physics/matter-js/PointerConstraint.js (Line 116)

scene :Phaser.Scene

A reference to the Scene to which this Pointer Constraint belongs. This is the same Scene as the Matter World instance.

Type:
Since: 3.0.0
Source: src/physics/matter-js/PointerConstraint.js (Line 63)

world :Phaser.Physics.Matter.World

A reference to the Matter World instance to which this Constraint belongs.

Type:
Since: 3.0.0
Source: src/physics/matter-js/PointerConstraint.js (Line 73)

Methods


destroy()

Destroys this Pointer Constraint instance and all of its references.

Since: 3.0.0
Source: src/physics/matter-js/PointerConstraint.js (Line 335)

getBody()

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.

Since: 3.16.2
Source: src/physics/matter-js/PointerConstraint.js (Line 183)
Returns:

true if a body was found and set, otherwise false.

Type
boolean

hitTestBody(body, position)

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.

Parameters:
Name Type Description
body MatterJS.Body

The Matter Body to check.

position Phaser.Math.Vector2

A translated hit test position.

Since: 3.16.2
Source: src/physics/matter-js/PointerConstraint.js (Line 222)
Returns:

true if a part of the body was hit, otherwise false.

Type
boolean

onDown(pointer)

A Pointer has been pressed down onto the Scene.

If this Constraint doesn't have an active Pointer then a hit test is run against all active bodies in the world. If one is found it is bound to this constraint and the drag begins.

Parameters:
Name Type Description
pointer Phaser.Input.Pointer

A reference to the Pointer that was pressed.

Since: 3.0.0
Source: src/physics/matter-js/PointerConstraint.js (Line 157)
Fires:

stopDrag()

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.

Since: 3.16.2
Source: src/physics/matter-js/PointerConstraint.js (Line 307)
Fires:

update()

Internal update handler. Called in the Matter BEFORE_UPDATE step.

Since: 3.0.0
Source: src/physics/matter-js/PointerConstraint.js (Line 269)
Fires: