Class: Pointer

Phaser.Input. Pointer

A Pointer object encapsulates both mouse and touch input within Phaser.

By default, Phaser will create 2 pointers for your game to use. If you require more, i.e. for a multi-touch
game, then use the InputPlugin.addPointer method to do so, rather than instantiating this class directly,
otherwise it won't be managed by the input system.

You can reference the current active pointer via InputPlugin.activePointer. You can also use the properties
InputPlugin.pointer1 through to pointer10, for each pointer you have enabled in your game.

The properties of this object are set by the Input Plugin during processing. This object is then sent in all
input related events that the Input Plugin emits, so you can reference properties from it directly in your
callbacks.


new Pointer(manager, id)

Parameters:
Name Type Description
manager Phaser.Input.InputManager

A reference to the Input Manager.

id integer

The internal ID of this Pointer.

Since: 3.0.0
Source: src/input/Pointer.js (Line 12)

Members


active :boolean

An active Pointer is one that is currently pressed down on the display.
A Mouse is always considered as active.

Type:
  • boolean
Since: 3.10.0
Source: src/input/Pointer.js (Line 338)

buttons :integer

0: No button or un-initialized
1: Left button
2: Right button
4: Wheel button or middle button
8: 4th button (typically the "Browser Back" button)
16: 5th button (typically the "Browser Forward" button)

For a mouse configured for left-handed use, the button actions are reversed.
In this case, the values are read from right to left.

Type:
  • integer
Since: 3.0.0
Default Value:
  • 0
Source: src/input/Pointer.js (Line 82)

camera :Phaser.Cameras.Scene2D.Camera

The camera the Pointer interacted with during its last update.

A Pointer can only ever interact with one camera at once, which will be the top-most camera
in the list should multiple cameras be positioned on-top of each other.

Type:
Since: 3.0.0
Default Value:
  • null
Source: src/input/Pointer.js (Line 69)

dirty :boolean

A dirty flag for this Pointer, used internally by the Input Plugin.

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/input/Pointer.js (Line 237)

downTime :number

Time when Button 1 (left button), or Touch, was pressed, used for dragging objects.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/input/Pointer.js (Line 163)

downX :number

X coordinate of the Pointer when Button 1 (left button), or Touch, was pressed, used for dragging objects.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/input/Pointer.js (Line 143)

downY :number

Y coordinate of the Pointer when Button 1 (left button), or Touch, was pressed, used for dragging objects.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/input/Pointer.js (Line 153)

dragState :number

The Drag State of the Pointer:

0 = Not dragging anything
1 = Being checked if dragging
2 = Dragging something

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/input/Pointer.js (Line 213)

event :TouchEvent|MouseEvent

The most recent native DOM Event this Pointer has processed.

Type:
  • TouchEvent | MouseEvent
Since: 3.0.0
Source: src/input/Pointer.js (Line 60)

<readonly> id :integer

The internal ID of this Pointer.

Type:
  • integer
Since: 3.0.0
Source: src/input/Pointer.js (Line 50)

identifier :number

The identifier property of the Pointer as set by the DOM event when this Pointer is started.

Type:
  • number
Since: 3.10.0
Source: src/input/Pointer.js (Line 319)

isDown :boolean

Is any button on this pointer considered as being down?

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/input/Pointer.js (Line 227)

justDown :boolean

Is this Pointer considered as being "just down" or not?

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/input/Pointer.js (Line 247)

justMoved :boolean

Is this Pointer considered as being "just moved" or not?

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/input/Pointer.js (Line 267)

justUp :boolean

Is this Pointer considered as being "just up" or not?

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/input/Pointer.js (Line 257)

manager :Phaser.Input.InputManager

A reference to the Input Manager.

Type:
Since: 3.0.0
Source: src/input/Pointer.js (Line 41)

movementX :number

If the mouse is locked, the horizontal relative movement of the Pointer in pixels since last frame.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/input/Pointer.js (Line 299)

movementY :number

If the mouse is locked, the vertical relative movement of the Pointer in pixels since last frame.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/input/Pointer.js (Line 309)

pointerId :number

The pointerId property of the Pointer as set by the DOM event when this Pointer is started.
The browser can and will recycle this value.

Type:
  • number
Since: 3.10.0
Source: src/input/Pointer.js (Line 328)

position :Phaser.Math.Vector2

The position of the Pointer in screen space.

Type:
Since: 3.0.0
Source: src/input/Pointer.js (Line 100)

prevPosition :Phaser.Math.Vector2

The previous position of the Pointer in screen space.

The old x and y values are stored in here during the InputManager.transformPointer call.

You can use it to track how fast the pointer is moving, or to smoothly interpolate between the old and current position.
See the Pointer.getInterpolatedPosition method to assist in this.

Type:
Since: 3.11.0
Source: src/input/Pointer.js (Line 109)

primaryDown :boolean

Is the primary button down? (usually button 0, the left mouse button)

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/input/Pointer.js (Line 203)

upTime :number

Time when Button 1 (left button), or Touch, was released, used for dragging objects.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/input/Pointer.js (Line 193)

upX :number

X coordinate of the Pointer when Button 1 (left button), or Touch, was released, used for dragging objects.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/input/Pointer.js (Line 173)

upY :number

Y coordinate of the Pointer when Button 1 (left button), or Touch, was released, used for dragging objects.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/input/Pointer.js (Line 183)

wasCanceled :boolean

Did this Pointer get canceled by a touchcancel event?

Note: "canceled" is the American-English spelling of "cancelled". Please don't submit PRs correcting it!

Type:
  • boolean
Since: 3.15.0
Default Value:
  • false
Source: src/input/Pointer.js (Line 287)

wasTouch :boolean

Did the previous input event come from a Touch input (true) or Mouse? (false)

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/input/Pointer.js (Line 277)

worldX :number

The x position of this Pointer, translated into the coordinate space of the most recent Camera it interacted with.

Type:
  • number
Since: 3.10.0
Default Value:
  • 0
Source: src/input/Pointer.js (Line 123)

worldY :number

The y position of this Pointer, translated into the coordinate space of the most recent Camera it interacted with.

Type:
  • number
Since: 3.10.0
Default Value:
  • 0
Source: src/input/Pointer.js (Line 133)

x :number

The x position of this Pointer.
The value is in screen space.
See worldX to get a camera converted position.

Type:
  • number
Since: 3.0.0
Source: src/input/Pointer.js (Line 785)

y :number

The y position of this Pointer.
The value is in screen space.
See worldY to get a camera converted position.

Type:
  • number
Since: 3.0.0
Source: src/input/Pointer.js (Line 808)

Methods


backButtonDown()

Checks to see if the back button is being held down on this Pointer.

Since: 3.0.0
Source: src/input/Pointer.js (Line 681)
Returns:

true if the back button is being held down.

Type
boolean

destroy()

Destroys this Pointer instance and resets its external references.

Since: 3.0.0
Source: src/input/Pointer.js (Line 772)

forwardButtonDown()

Checks to see if the forward button is being held down on this Pointer.

Since: 3.0.0
Source: src/input/Pointer.js (Line 694)
Returns:

true if the forward button is being held down.

Type
boolean

getDistance()

Returns the distance between the Pointer's current position and where it was
first pressed down (the downX and downY properties)

Since: 3.13.0
Source: src/input/Pointer.js (Line 707)
Returns:

The distance the Pointer has moved since being pressed down.

Type
number

getInterpolatedPosition( [steps] [, out])

Takes the previous and current Pointer positions and then generates an array of interpolated values between
the two. The array will be populated up to the size of the steps argument.

var points = pointer.getInterpolatedPosition(4);

// points[0] = { x: 0, y: 0 }
// points[1] = { x: 2, y: 1 }
// points[2] = { x: 3, y: 2 }
// points[3] = { x: 6, y: 3 }

Use this if you need to get smoothed values between the previous and current pointer positions. DOM pointer
events can often fire faster than the main browser loop, and this will help you avoid janky movement
especially if you have an object following a Pointer.

Note that if you provide an output array it will only be populated up to the number of steps provided.
It will not clear any previous data that may have existed beyond the range of the steps count.

Internally it uses the Smooth Step interpolation calculation.

Parameters:
Name Type Argument Default Description
steps integer <optional>
10

The number of interpolation steps to use.

out array <optional>

An array to store the results in. If not provided a new one will be created.

Since: 3.11.0
Source: src/input/Pointer.js (Line 721)
Returns:

An array of interpolated values.

Type
array

leftButtonDown()

Checks to see if the left button is being held down on this Pointer.

Since: 3.0.0
Source: src/input/Pointer.js (Line 642)
Returns:

true if the left button is being held down.

Type
boolean

middleButtonDown()

Checks to see if the middle button is being held down on this Pointer.

Since: 3.0.0
Source: src/input/Pointer.js (Line 668)
Returns:

true if the middle button is being held down.

Type
boolean

noButtonDown()

Checks to see if any buttons are being held down on this Pointer.

Since: 3.0.0
Source: src/input/Pointer.js (Line 629)
Returns:

true if no buttons are being held down.

Type
boolean

positionToCamera(camera [, output])

Takes a Camera and returns a Vector2 containing the translated position of this Pointer
within that Camera. This can be used to convert this Pointers position into camera space.

Parameters:
Name Type Argument Description
camera Phaser.Cameras.Scene2D.Camera

The Camera to use for the translation.

output Phaser.Math.Vector2 | object <optional>

A Vector2-like object in which to store the translated position.

Since: 3.0.0
Source: src/input/Pointer.js (Line 349)
Returns:

A Vector2 containing the translated coordinates of this Pointer, based on the given camera.

Type
Phaser.Math.Vector2 | object

rightButtonDown()

Checks to see if the right button is being held down on this Pointer.

Since: 3.0.0
Source: src/input/Pointer.js (Line 655)
Returns:

true if the right button is being held down.

Type
boolean