These archived docs are for Phaser 2.2.2 Phaser 3 docs can be found on newdocs.phaser.io.
Phaser CE docs can be found on the Phaser CE Documentation site.

Constructor

Phaser. Input

new Input(game)

Phaser.Input is the Input Manager for all types of Input across Phaser, including mouse, keyboard, touch and MSPointer. The Input manager is updated automatically by the core game loop.

Parameters
Name Type Description
game Phaser.Game

Current game instance.

Source code: input/Input.js, line 15

Public Properties

[static] MAX_POINTERS : integer

The maximum number of pointers that can be added. This excludes the mouse pointer.

Source code: input/Input.js, line 347

[static] MOUSE_OVERRIDES_TOUCH : number

Source code: input/Input.js, line 328

[static] MOUSE_TOUCH_COMBINE : number

Source code: input/Input.js, line 340

[static] TOUCH_OVERRIDES_MOUSE : number

Source code: input/Input.js, line 334

activePointer : Phaser.Pointer

The most recently active Pointer object. When you've limited max pointers to 1 this will accurately be either the first finger touched or mouse.

Source code: input/Input.js, line 222

circle : Phaser.Circle

A Circle object centered on the x/y screen coordinates of the Input. Default size of 44px (Apples recommended "finger tip" size) but can be changed to anything.

Source code: input/Input.js, line 86

currentPointers : number

This method is deprecated and should not be used. It may be removed in the future.

The current number of active Pointers.

Deprecated:
  • This is only updated when `maxPointers >= 0` and will generally be innacurate. Use `totalActivePointers` instead.
Source code: input/Input.js, line 103

doubleTapRate : number

The number of milliseconds between taps of the same Pointer for it to be considered a double tap / click.

Default Value
  • 300
Source code: input/Input.js, line 115

enabled : boolean

When enabled, input (eg. Keyboard, Mouse, Touch) will be processed - as long as the individual sources are enabled themselves.

When not enabled, all input sources are ignored. To disable just one type of input; for example, the Mouse, use input.mouse.enabled = false.

Default Value
  • true
Source code: input/Input.js, line 62

game : Phaser.Game

A reference to the currently running game.

Source code: input/Input.js, line 20

gamepad : Phaser.Gamepad

The Gamepad Input manager.

Source code: input/Input.js, line 252

hitCanvas :HTMLCanvasElement

The canvas to which single pixels are drawn in order to perform pixel-perfect hit detection.

Default Value
  • null
Source code: input/Input.js, line 26

hitContext :CanvasRenderingContext2D

The context of the pixel perfect hit canvas.

Default Value
  • null
Source code: input/Input.js, line 32

holdRate : number

The number of milliseconds that the Pointer has to be pressed down for it to fire a onHold event.

Default Value
  • 2000
Source code: input/Input.js, line 121

interactiveItems : Phaser.ArraySet

A list of interactive objects. The InputHandler components add and remove themselves from this list.

Source code: input/Input.js, line 290

justPressedRate : number

The number of milliseconds below which the Pointer is considered justPressed.

Default Value
  • 200
Source code: input/Input.js, line 127

justReleasedRate : number

The number of milliseconds below which the Pointer is considered justReleased .

Default Value
  • 200
Source code: input/Input.js, line 133

keyboard : Phaser.Keyboard

The Keyboard Input manager.

Source code: input/Input.js, line 237

maxPointers : integer

The maximum number of Pointers allowed to be active at any one time. A value of -1 is only limited by the total number of pointers. For lots of games it's useful to set this to 1.

Default Value
  • -1 (Limited by total pointers.)
Source code: input/Input.js, line 97

minPriorityID : number

You can tell all Pointers to ignore any object with a priorityID lower than the minPriorityID. Useful when stacking UI layers. Set to zero to disable.

Default Value
  • 0
Source code: input/Input.js, line 284

mouse : Phaser.Mouse

The Mouse Input manager.

Source code: input/Input.js, line 232

mousePointer :Pointer

The mouse has its own unique Phaser.Pointer object which you can use if making a desktop specific game.

Source code: input/Input.js, line 227

moveCallback : Function

An optional callback that will be fired every time the activePointer receives a move event from the DOM. Set to null to disable.

Source code: input/Input.js, line 42

moveCallbackContext : Object

The context in which the moveCallback will be sent. Defaults to Phaser.Input but can be set to any valid JS object.

Source code: input/Input.js, line 47

moveCallbacks :array

An array of callbacks that will be fired every time the activePointer receives a move event from the DOM.

Source code: input/Input.js, line 37

mspointer : Phaser.MSPointer

The MSPointer Input manager.

Source code: input/Input.js, line 247

multiInputOverride : number

Controls the expected behaviour when using a mouse and touch together on a multi-input device.

Source code: input/Input.js, line 68

onDown : Phaser.Signal

A Signal that is dispatched each time a pointer is pressed down.

Source code: input/Input.js, line 263

onHold : Phaser.Signal

A Signal that is dispatched each time a pointer is held down.

Source code: input/Input.js, line 278

onTap : Phaser.Signal

A Signal that is dispatched each time a pointer is tapped.

Source code: input/Input.js, line 273

onUp : Phaser.Signal

A Signal that is dispatched each time a pointer is released.

Source code: input/Input.js, line 268

pointer1 : Phaser.Pointer

A Pointer object.

Source code: input/Input.js, line 161

pointer2 : Phaser.Pointer

A Pointer object.

Source code: input/Input.js, line 166

pointer3 : Phaser.Pointer

A Pointer object.

Source code: input/Input.js, line 171

pointer4 : Phaser.Pointer

A Pointer object.

Source code: input/Input.js, line 176

pointer5 : Phaser.Pointer

A Pointer object.

Source code: input/Input.js, line 181

pointer6 : Phaser.Pointer

A Pointer object.

Source code: input/Input.js, line 186

pointer7 : Phaser.Pointer

A Pointer object.

Source code: input/Input.js, line 191

pointer8 : Phaser.Pointer

A Pointer object.

Source code: input/Input.js, line 196

pointer9 : Phaser.Pointer

A Pointer object.

Source code: input/Input.js, line 201

pointer10 : Phaser.Pointer

A Pointer object.

Source code: input/Input.js, line 206

[readonly] pointers :Phaser.Pointer[]

An array of non-mouse pointers that have been added to the game. The properties pointer1..N are aliases for pointers[0..N-1].

Type
  • Phaser.Pointer[]
Source code: input/Input.js, line 215

[readonly] pollLocked : boolean

True if the Input is currently poll rate locked.

Source code: input/Input.js, line 955

pollRate : number

How often should the input pointers be checked for updates? A value of 0 means every single frame (60fps); a value of 1 means every other frame (30fps) and so on.

Default Value
  • 0
Source code: input/Input.js, line 53

position : Phaser.Point

A point object representing the current position of the Pointer.

Default Value
  • null
Source code: input/Input.js, line 74

recordLimit : number

The total number of entries that can be recorded into the Pointer objects tracking history. If the Pointer is tracking one event every 100ms; then a trackLimit of 100 would store the last 10 seconds worth of history.

Default Value
  • 100
Source code: input/Input.js, line 156

recordPointerHistory : boolean

Sets if the Pointer objects should record a history of x/y coordinates they have passed through. The history is cleared each time the Pointer is pressed down. The history is updated at the rate specified in Input.pollRate

Default Value
  • false
Source code: input/Input.js, line 142

recordRate : number

The rate in milliseconds at which the Pointer objects should update their tracking history.

Default Value
  • 100
Source code: input/Input.js, line 148

resetLocked : boolean

If the Input Manager has been reset locked then all calls made to InputManager.reset, such as from a State change, are ignored.

Default Value
  • false
Source code: input/Input.js, line 258

scale : Phaser.Point

The scale by which all input coordinates are multiplied; calculated by the ScaleManager. In an un-scaled game the values will be x = 1 and y = 1.

Source code: input/Input.js, line 91

speed : Phaser.Point

A point object representing the speed of the Pointer. Only really useful in single Pointer games; otherwise see the Pointer objects directly.

Source code: input/Input.js, line 79

tapRate : number

The number of milliseconds that the Pointer has to be pressed down and then released to be considered a tap or click.

Default Value
  • 200
Source code: input/Input.js, line 109

[readonly] totalActivePointers : integers

The total number of active Pointers, not counting the mouse pointer.

Source code: input/Input.js, line 983

[readonly] totalInactivePointers : number

The total number of inactive Pointers.

Source code: input/Input.js, line 969

touch : Phaser.Touch

the Touch Input manager.

Source code: input/Input.js, line 242

[readonly] worldX : number

The world X coordinate of the most recently active pointer.

Source code: input/Input.js, line 997

[readonly] worldY : number

The world Y coordinate of the most recently active pointer.

Source code: input/Input.js, line 1011

x : number

The X coordinate of the most recently active pointer. This value takes game scaling into account automatically. See Pointer.screenX/clientX for source values.

Source code: input/Input.js, line 919

y : number

The Y coordinate of the most recently active pointer. This value takes game scaling into account automatically. See Pointer.screenY/clientY for source values.

Source code: input/Input.js, line 937

Public Methods

addMoveCallback(callback, context) → {number}

Adds a callback that is fired every time the activePointer receives a DOM move event such as a mousemove or touchmove.

The callback will be sent 4 parameters: The Pointer that moved, the x position of the pointer, the y position and the down state. It will be called every time the activePointer moves, which in a multi-touch game can be a lot of times, so this is best to only use if you've limited input to a single pointer (i.e. mouse or touch). The callback is added to the Phaser.Input.moveCallbacks array and should be removed with Phaser.Input.deleteMoveCallback.

Parameters
Name Type Description
callback function

The callback that will be called each time the activePointer receives a DOM move event.

context object

The context in which the callback will be called.

Returns
number -

The index of the callback entry. Use this index when calling Input.deleteMoveCallback.

Source code: input/Input.js, line 423

addPointer() → {Phaser.Pointer | null}

Add a new Pointer object to the Input Manager. By default Input creates 3 pointer objects: mousePointer (not include in part of general pointer pool), pointer1 and pointer2. This method adds an additional pointer, up to a maximum of Phaser.Input.MAX_POINTERS (default of 10).

Returns
Phaser.Pointer | null -

The new Pointer object that was created; null if a new pointer could not be added.

Source code: input/Input.js, line 458

<internal> boot()

Starts the Input Manager running.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source code: input/Input.js, line 351

deleteMoveCallback(index)

Removes the callback at the defined index from the Phaser.Input.moveCallbacks array

Parameters
Name Type Description
index number

The index of the callback to remove.

Source code: input/Input.js, line 443

destroy()

Stops all of the Input Managers from running.

Source code: input/Input.js, line 404

getLocalPosition(displayObject, pointer) → {Phaser.Point}

This will return the local coordinates of the specified displayObject based on the given Pointer.

Parameters
Name Type Description
displayObject Phaser.Sprite | Phaser.Image

The DisplayObject to get the local coordinates for.

pointer Phaser.Pointer

The Pointer to use in the check against the displayObject.

Returns

A point containing the coordinates of the Pointer position relative to the DisplayObject.

Source code: input/Input.js, line 792

getPointer(isActive) → {Phaser.Pointer}

Get the first Pointer with the given active state.

Parameters
Name Type Argument Default Description
isActive boolean <optional>
false

The state the Pointer should be in - active or innactive?

Returns

A Pointer object or null if no Pointer object matches the requested state.

Source code: input/Input.js, line 716

getPointerFromId(pointerId) → {Phaser.Pointer}

Get the Pointer object whos pointerId property matches the given value.

The pointerId property is not set until the Pointer has been used at least once, as its populated by the DOM event. Also it can change every time you press the pointer down if the browser recycles it.

Parameters
Name Type Description
pointerId number

The pointerId (not 'id') value to search for.

Returns

A Pointer object or null if no Pointer object matches the requested identifier.

Source code: input/Input.js, line 766

getPointerFromIdentifier(identifier) → {Phaser.Pointer}

Get the Pointer object whos identifier property matches the given identifier value.

The identifier property is not set until the Pointer has been used at least once, as its populated by the DOM event. Also it can change every time you press the pointer down, and is not fixed once set. Note: Not all browsers set the identifier property and it's not part of the W3C spec, so you may need getPointerFromId instead.

Parameters
Name Type Description
identifier number

The Pointer.identifier value to search for.

Returns

A Pointer object or null if no Pointer object matches the requested identifier.

Source code: input/Input.js, line 740

hitTest(displayObject, pointer, localPoint)

Tests if the pointer hits the given object.

Parameters
Name Type Description
displayObject DisplayObject

The displayObject to test for a hit.

pointer Phaser.Pointer

The pointer to use for the test.

localPoint Phaser.Point

The local translated point.

Source code: input/Input.js, line 814

reset(hard)

Reset all of the Pointers and Input states.

The optional hard parameter will reset any events or callbacks that may be bound. Input.reset is called automatically during a State change or if a game loses focus / visibility. To control control the reset manually set Phaser.InputManager.resetLocked to true.

Parameters
Name Type Argument Default Description
hard boolean <optional>
false

A soft reset won't reset any events or callbacks that are bound. A hard reset will.

Source code: input/Input.js, line 517

resetSpeed(x, y)

Resets the speed and old position properties.

Parameters
Name Type Description
x number

Sets the oldPosition.x value.

y number

Sets the oldPosition.y value.

Source code: input/Input.js, line 570

<internal> startPointer(event) → {Phaser.Pointer}

Find the first free Pointer object and start it, passing in the event data. This is called automatically by Phaser.Touch and Phaser.MSPointer.

Parameters
Name Type Description
event any

The event data from the Touch event.

Returns

The Pointer object that was started or null if no Pointer object is available.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source code: input/Input.js, line 584

<internal> stopPointer(event) → {Phaser.Pointer}

Stops the matching Pointer object, passing in the event data.

Parameters
Name Type Description
event any

The event data from the Touch event.

Returns

The Pointer object that was stopped or null if no Pointer object is available.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source code: input/Input.js, line 655

<internal> update()

Updates the Input Manager. Called by the core Game loop.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source code: input/Input.js, line 484

<internal> updatePointer(event) → {Phaser.Pointer}

Updates the matching Pointer object, passing in the event data. This is called automatically and should not normally need to be invoked.

Parameters
Name Type Description
event any

The event data from the Touch event.

Returns

The Pointer object that was updated; null if no pointer was updated.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source code: input/Input.js, line 622