Phaser.Touch

new Touch(game)

Phaser.Touch handles touch events with your game. Note: Android 2.x only supports 1 touch event at once, no multi-touch.

You should not normally access this class directly, but instead use a Phaser.Pointer object which normalises all game input for you.

Parameters:

Name

Type

Description

game

Phaser.Game

A reference to the currently running game.

Source - input/Touch.js, line 16

Members

callbackContext:object

The context under which callbacks are called.

Source - input/Touch.js, line 42

enabled:boolean

Touch events will only be processed if enabled.

Default Value: - true

Source - input/Touch.js, line 28

event:TouchEvent

The browser touch DOM event. Will be set to null if no touch event has ever been received.

Source - input/Touch.js, line 84

game:Phaser.Game

A reference to the currently running game.

Source - input/Touch.js, line 21

preventDefault:boolean

If true the TouchEvent will have prevent.default called on it.

Default Value: - true

Source - input/Touch.js, line 78

touchCancelCallback:function

A callback that can be fired on a touchCancel event.

Source - input/Touch.js, line 72

touchEndCallback:function

A callback that can be fired on a touchEnd event.

Source - input/Touch.js, line 57

touchEnterCallback:function

A callback that can be fired on a touchEnter event.

Source - input/Touch.js, line 62

touchLeaveCallback:function

A callback that can be fired on a touchLeave event.

Source - input/Touch.js, line 67

<internal>touchLockCallbacks:array

An array of callbacks that will be fired every time a native touch start or touch end event is received from the browser. This is used internally to handle audio and video unlocking on mobile devices. To add a callback to this array please use Touch.addTouchLockCallback.

Internal: - This member is internal (protected) and may be modified or removed in the future.

Source - input/Touch.js, line 37

touchMoveCallback:function

A callback that can be fired on a touchMove event.

Source - input/Touch.js, line 52

touchStartCallback:function

A callback that can be fired on a touchStart event.

Source - input/Touch.js, line 47

addTouchLockCallback(callback, context, onEnd)

Adds a callback that is fired when a browser touchstart or touchend event is received.

This is used internally to handle audio and video unlocking on mobile devices.

If the callback returns 'true' then the callback is automatically deleted once invoked.

The callback is added to the Phaser.Touch.touchLockCallbacks array and should be removed with Phaser.Touch.removeTouchLockCallback.

Parameters:

Name

Type

Argument

Default

Description

callback

function

The callback that will be called when a touchstart event is received.

context

object

The context in which the callback will be called.

onEnd

boolean

<optional>

false

Will the callback fire on a touchstart (default) or touchend event?

Source - input/Touch.js, line 200

consumeTouchMove()

Consumes all touchmove events on the document (only enable this if youknow you need it!).

Source - input/Touch.js, line 186

onTouchCancel(event)

Touch cancel - touches that were disrupted (perhaps by moving into aplugin or browser chrome). Occurs for example on iOS when you put down 4 fingers and the app selector UI appears.

Parameters:

Name

Type

Description

event

TouchEvent

The native event from the browser. This gets stored in Touch.event.

Source - input/Touch.js, line 293

onTouchEnd(event)

The handler for the touchend events.

Parameters:

Name

Type

Description

event

TouchEvent

The native event from the browser. This gets stored in Touch.event.

Source - input/Touch.js, line 402

onTouchEnter(event)

For touch enter and leave its a list of the touch points that have entered or left the target. Doesn't appear to be supported by most browsers on a canvas element yet.

Parameters:

Name

Type

Description

event

TouchEvent

The native event from the browser. This gets stored in Touch.event.

Source - input/Touch.js, line 327

onTouchLeave(event)

For touch enter and leave its a list of the touch points that have entered or left the target. Doesn't appear to be supported by most browsers on a canvas element yet.

Parameters:

Name

Type

Description

event

TouchEvent

The native event from the browser. This gets stored in Touch.event.

Source - input/Touch.js, line 354

onTouchMove(event)

The handler for the touchmove events.

Parameters:

Name

Type

Description

event

TouchEvent

The native event from the browser. This gets stored in Touch.event.

Source - input/Touch.js, line 376

onTouchStart(event)

The internal method that handles the touchstart event from the browser.

Parameters:

Name

Type

Description

event

TouchEvent

The native event from the browser. This gets stored in Touch.event.

Source - input/Touch.js, line 247

removeTouchLockCallback(callback, context)→ {boolean}

Removes the callback at the defined index from the Phaser.Touch.touchLockCallbacks array

Parameters:

Name

Type

Description

callback

function

The callback to be removed.

context

object

The context in which the callback exists.

Returns:

boolean-

True if the callback was deleted, otherwise false.

Source - input/Touch.js, line 222

start()

Starts the event listeners running.

Source - input/Touch.js, line 132

stop()

Stop the event listeners.

Source - input/Touch.js, line 443