Phaser API Documentation

  Version: 
Filter

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.

Constructor:

new PointerConstraint(scene, world, [options])

Parameters:

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.

Since: 3.0.0

Members

active: boolean
Focus
Focus

Description:

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
Default: true
Since: 3.0.0
Focus
Focus
<nullable> body: MatterJS.BodyType
Focus
Focus

Description:

The body that is currently being dragged, if any.

Type:
MatterJS.BodyType
Since: 3.16.2
Focus
Focus

Description:

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

Type:
Since: 3.0.0
Focus
Focus
constraint: MatterJS.ConstraintType
Focus
Focus

Description:

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

Type:
MatterJS.ConstraintType
Since: 3.0.0
Focus
Focus
<nullable> part: MatterJS.BodyType
Focus
Focus

Description:

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

Type:
MatterJS.BodyType
Since: 3.16.2
Focus
Focus

Description:

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

Type:
Default: null
Since: 3.0.0
Focus
Focus

Description:

The internal transformed position.

Type:
Since: 3.0.0
Focus
Focus
scene: Phaser.Scene
Focus
Focus

Description:

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
Focus
Focus

Description:

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

Type:
Since: 3.0.0
Focus
Focus

Methods

destroy()
Focus
Focus

Description:

Destroys this Pointer Constraint instance and all of its references.

Since: 3.0.0
Focus
Focus
getBody()
Focus
Focus

Description:

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.

Returns:
Description:

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

Type:
  • boolean
Since: 3.16.2
Focus
Focus
hitTestBody(body, position)
Focus
Focus

Description:

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.

Returns:
Description:

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

Type:
  • boolean
Since: 3.16.2
Focus
Focus
onDown(pointer)
Focus
Focus

Description:

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
Focus
Focus
onUp(pointer)
Focus
Focus

Description:

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
Focus
Focus
stopDrag()
Focus
Focus

Description:

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
Focus
Focus
update()
Focus
Focus

Description:

Internal update handler. Called in the Matter BEFORE_UPDATE step.

Since: 3.0.0
Focus
Focus