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

<nullable> body :MatterJS.BodyType

The body that is currently being dragged, if any.

Type:
  • MatterJS.BodyType
Since: 3.16.2
Source: src/physics/matter-js/PointerConstraint.js (Line 124)

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

constraint :MatterJS.ConstraintType

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

Type:
  • MatterJS.ConstraintType
Since: 3.0.0
Source: src/physics/matter-js/PointerConstraint.js (Line 142)

<nullable> part :MatterJS.BodyType

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

Type:
  • MatterJS.BodyType
Since: 3.16.2
Source: src/physics/matter-js/PointerConstraint.js (Line 133)

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

position :Phaser.Math.Vector2

The internal transformed position.

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

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

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

Methods


destroy()

Destroys this Pointer Constraint instance and all of its references.

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

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 194)
Fires:
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.BodyType

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 234)
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 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.

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)

onUp(pointer)

A Pointer has been released from the Scene. If it was the one this constraint was using, it's cleared.

Parameters:
Name Type Description
pointer Phaser.Input.Pointer

A reference to the Pointer that was pressed.

Since: 3.22.0
Source: src/physics/matter-js/PointerConstraint.js (Line 178)

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 330)
Fires:

update()

Internal update handler. Called in the Matter BEFORE_UPDATE step.

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