Touch
Class: Phaser.Touch
Constructor
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
- Source code: input/Touch.js (Line 42)
- Default Value
- true
- Source code: input/Touch.js (Line 28)
- Source code: input/Touch.js (Line 84)
- Source code: input/Touch.js (Line 21)
- Default Value
- true
- Source code: input/Touch.js (Line 78)
- Source code: input/Touch.js (Line 72)
- Source code: input/Touch.js (Line 57)
- Source code: input/Touch.js (Line 62)
- Source code: input/Touch.js (Line 67)
- Internal:
- This member is internal (protected) and may be modified or removed in the future.
- Source code: input/Touch.js (Line 37)
- Source code: input/Touch.js (Line 52)
- Source code: input/Touch.js (Line 47)
callbackContext : Object
The context under which callbacks are called.
enabled : boolean
Touch events will only be processed if enabled.
event :TouchEvent
The browser touch DOM event. Will be set to null if no touch event has ever been received.
game : Phaser.Game
A reference to the currently running game.
preventDefault : boolean
If true the TouchEvent will have prevent.default called on it.
touchCancelCallback : Function
A callback that can be fired on a touchCancel event.
touchEndCallback : Function
A callback that can be fired on a touchEnd event.
touchEnterCallback : Function
A callback that can be fired on a touchEnter event.
touchLeaveCallback : Function
A callback that can be fired on a touchLeave event.
<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
.
touchMoveCallback : Function
A callback that can be fired on a touchMove event.
touchStartCallback : Function
A callback that can be fired on a touchStart event.
Public Methods
- Source code: input/Touch.js (Line 200)
- Source code: input/Touch.js (Line 186)
- Source code: input/Touch.js (Line 293)
- Source code: input/Touch.js (Line 402)
- Source code: input/Touch.js (Line 327)
- Source code: input/Touch.js (Line 354)
- Source code: input/Touch.js (Line 376)
- Source code: input/Touch.js (Line 247)
- Source code: input/Touch.js (Line 222)
- Source code: input/Touch.js (Line 132)
- Source code: input/Touch.js (Line 443)
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? |
consumeTouchMove()
Consumes all touchmove events on the document (only enable this if you know you need it!).
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. |
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. |
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. |
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. |
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. |
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. |
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
True if the callback was deleted, otherwise false.
start()
Starts the event listeners running.
stop()
Stop the event listeners.
© 2016 Richard Davey, Photon Storm Ltd.
Licensed under the MIT License.
http://phaser.io/docs/2.6.2/Phaser.Touch.html