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 code: input/Touch.js (Line 16)
Public Properties
-
callbackContext : Object
-
The context under which callbacks are called.
- Source code: input/Touch.js (Line 42)
-
enabled : boolean
-
Touch events will only be processed if enabled.
- Default Value
- true
- Source code: 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 code: input/Touch.js (Line 84)
-
game : Phaser.Game
-
A reference to the currently running game.
- Source code: input/Touch.js (Line 21)
-
preventDefault : boolean
-
If true the TouchEvent will have prevent.default called on it.
- Default Value
- true
- Source code: input/Touch.js (Line 78)
-
touchCancelCallback : Function
-
A callback that can be fired on a touchCancel event.
- Source code: input/Touch.js (Line 72)
-
touchEndCallback : Function
-
A callback that can be fired on a touchEnd event.
- Source code: input/Touch.js (Line 57)
-
touchEnterCallback : Function
-
A callback that can be fired on a touchEnter event.
- Source code: input/Touch.js (Line 62)
-
touchLeaveCallback : Function
-
A callback that can be fired on a touchLeave event.
- Source code: input/Touch.js (Line 67)
-
<internal> touchLockCallbacks :array
-
An array of callbacks that will be fired every time a native touch start 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 code: input/Touch.js (Line 37)
-
touchMoveCallback : Function
-
A callback that can be fired on a touchMove event.
- Source code: input/Touch.js (Line 52)
-
touchStartCallback : Function
-
A callback that can be fired on a touchStart event.
- Source code: input/Touch.js (Line 47)
Public Methods
-
addTouchLockCallback(callback, context)
-
Adds a callback that is fired when a browser touchstart 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 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.
- Source code: input/Touch.js (Line 200)
-
consumeTouchMove()
-
Consumes all touchmove events on the document (only enable this if you know you need it!).
- Source code: input/Touch.js (Line 186)
-
onTouchCancel(event)
-
Touch cancel - touches that were disrupted (perhaps by moving into a plugin 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 code: input/Touch.js (Line 288)
-
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 code: input/Touch.js (Line 397)
-
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 code: input/Touch.js (Line 322)
-
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 code: input/Touch.js (Line 349)
-
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 code: input/Touch.js (Line 371)
-
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 code: input/Touch.js (Line 244)
-
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 code: input/Touch.js (Line 219)
-
start()
-
Starts the event listeners running.
- Source code: input/Touch.js (Line 132)
-
stop()
-
Stop the event listeners.
- Source code: input/Touch.js (Line 426)