mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 21:24:09 +00:00
Touch.addTouchLockCallback has a new argument onEnd
which allows the callback to fire either on a touchstart or a touchend event.
This commit is contained in:
parent
d86d01bd25
commit
27457c2b0f
1 changed files with 22 additions and 5 deletions
|
@ -28,7 +28,7 @@ Phaser.Touch = function (game) {
|
||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An array of callbacks that will be fired every time a native touch start event is received from the browser.
|
* 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.
|
* This is used internally to handle audio and video unlocking on mobile devices.
|
||||||
* To add a callback to this array please use `Touch.addTouchLockCallback`.
|
* To add a callback to this array please use `Touch.addTouchLockCallback`.
|
||||||
* @property {array} touchLockCallbacks
|
* @property {array} touchLockCallbacks
|
||||||
|
@ -198,7 +198,7 @@ Phaser.Touch.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a callback that is fired when a browser touchstart event is received.
|
* 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.
|
* This is used internally to handle audio and video unlocking on mobile devices.
|
||||||
*
|
*
|
||||||
|
@ -209,10 +209,13 @@ Phaser.Touch.prototype = {
|
||||||
* @method Phaser.Touch#addTouchLockCallback
|
* @method Phaser.Touch#addTouchLockCallback
|
||||||
* @param {function} callback - The callback that will be called when a touchstart event is received.
|
* @param {function} callback - The callback that will be called when a touchstart event is received.
|
||||||
* @param {object} context - The context in which the callback will be called.
|
* @param {object} context - The context in which the callback will be called.
|
||||||
|
* @param {boolean} [onEnd=false] - Will the callback fire on a touchstart (default) or touchend event?
|
||||||
*/
|
*/
|
||||||
addTouchLockCallback: function (callback, context) {
|
addTouchLockCallback: function (callback, context, onEnd) {
|
||||||
|
|
||||||
this.touchLockCallbacks.push({ callback: callback, context: context });
|
if (onEnd === undefined) { onEnd = false; }
|
||||||
|
|
||||||
|
this.touchLockCallbacks.push({ callback: callback, context: context, onEnd: onEnd });
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -252,7 +255,9 @@ Phaser.Touch.prototype = {
|
||||||
|
|
||||||
while (i--)
|
while (i--)
|
||||||
{
|
{
|
||||||
if (this.touchLockCallbacks[i].callback.call(this.touchLockCallbacks[i].context, this, event))
|
var cb = this.touchLockCallbacks[i];
|
||||||
|
|
||||||
|
if (!cb.onEnd && cb.callback.call(cb.context, this, event))
|
||||||
{
|
{
|
||||||
this.touchLockCallbacks.splice(i, 1);
|
this.touchLockCallbacks.splice(i, 1);
|
||||||
}
|
}
|
||||||
|
@ -401,6 +406,18 @@ Phaser.Touch.prototype = {
|
||||||
*/
|
*/
|
||||||
onTouchEnd: function (event) {
|
onTouchEnd: function (event) {
|
||||||
|
|
||||||
|
var i = this.touchLockCallbacks.length;
|
||||||
|
|
||||||
|
while (i--)
|
||||||
|
{
|
||||||
|
var cb = this.touchLockCallbacks[i];
|
||||||
|
|
||||||
|
if (cb.onEnd && cb.callback.call(cb.context, this, event))
|
||||||
|
{
|
||||||
|
this.touchLockCallbacks.splice(i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.event = event;
|
this.event = event;
|
||||||
|
|
||||||
if (this.touchEndCallback)
|
if (this.touchEndCallback)
|
||||||
|
|
Loading…
Reference in a new issue