Skip to content

Commit 4b50065

Browse files
committed
Touch Manager will track over and out canvas states.
1 parent 4a312f1 commit 4b50065

1 file changed

Lines changed: 58 additions & 11 deletions

File tree

src/input/touch/TouchManager.js

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,26 @@ var TouchManager = new Class({
112112
*/
113113
this.onTouchCancel = NOOP;
114114

115+
/**
116+
* The Touch Over event handler function.
117+
* Initially empty and bound in the `startListeners` method.
118+
*
119+
* @name Phaser.Input.Touch.TouchManager#onTouchOver
120+
* @type {function}
121+
* @since 3.16.0
122+
*/
123+
this.onTouchOver = NOOP;
124+
125+
/**
126+
* The Touch Out event handler function.
127+
* Initially empty and bound in the `startListeners` method.
128+
*
129+
* @name Phaser.Input.Touch.TouchManager#onTouchOut
130+
* @type {function}
131+
* @since 3.16.0
132+
*/
133+
this.onTouchOut = NOOP;
134+
115135
inputManager.events.once('boot', this.boot, this);
116136
},
117137

@@ -219,6 +239,28 @@ var TouchManager = new Class({
219239
}
220240
};
221241

242+
this.onTouchOver = function (event)
243+
{
244+
if (event.defaultPrevented || !_this.enabled || !_this.manager)
245+
{
246+
// Do nothing if event already handled
247+
return;
248+
}
249+
250+
_this.manager.setCanvasOver(event);
251+
};
252+
253+
this.onTouchOut = function (event)
254+
{
255+
if (event.defaultPrevented || !_this.enabled || !_this.manager)
256+
{
257+
// Do nothing if event already handled
258+
return;
259+
}
260+
261+
_this.manager.setCanvasOut(event);
262+
};
263+
222264
var target = this.target;
223265

224266
if (!target)
@@ -229,18 +271,16 @@ var TouchManager = new Class({
229271
var passive = { passive: true };
230272
var nonPassive = { passive: false };
231273

232-
if (this.capture)
233-
{
234-
target.addEventListener('touchstart', this.onTouchStart, nonPassive);
235-
target.addEventListener('touchmove', this.onTouchMove, nonPassive);
236-
target.addEventListener('touchend', this.onTouchEnd, nonPassive);
237-
target.addEventListener('touchcancel', this.onTouchCancel, nonPassive);
238-
}
239-
else
274+
target.addEventListener('touchstart', this.onTouchStart, (this.capture) ? nonPassive : passive);
275+
target.addEventListener('touchmove', this.onTouchMove, (this.capture) ? nonPassive : passive);
276+
target.addEventListener('touchend', this.onTouchEnd, (this.capture) ? nonPassive : passive);
277+
target.addEventListener('touchcancel', this.onTouchCancel, (this.capture) ? nonPassive : passive);
278+
target.addEventListener('touchover', this.onTouchOver, (this.capture) ? nonPassive : passive);
279+
target.addEventListener('touchout', this.onTouchOut, (this.capture) ? nonPassive : passive);
280+
281+
if (window)
240282
{
241-
target.addEventListener('touchstart', this.onTouchStart, passive);
242-
target.addEventListener('touchmove', this.onTouchMove, passive);
243-
target.addEventListener('touchend', this.onTouchEnd, passive);
283+
window.addEventListener('touchend', this.onTouchEnd, nonPassive);
244284
}
245285

246286
this.enabled = true;
@@ -261,6 +301,13 @@ var TouchManager = new Class({
261301
target.removeEventListener('touchmove', this.onTouchMove);
262302
target.removeEventListener('touchend', this.onTouchEnd);
263303
target.removeEventListener('touchcancel', this.onTouchCancel);
304+
target.removeEventListener('touchover', this.onTouchOver);
305+
target.removeEventListener('touchout', this.onTouchOut);
306+
307+
if (window)
308+
{
309+
window.removeEventListener('touchend', this.onTouchEnd);
310+
}
264311
},
265312

266313
/**

0 commit comments

Comments
 (0)