Skip to content

Commit 341e78c

Browse files
committed
Added touch Window handlers and remove handlers
1 parent c90ae09 commit 341e78c

4 files changed

Lines changed: 59 additions & 14 deletions

File tree

src/core/Config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ var Config = new Class({
276276
this.inputQueue = GetValue(config, 'input.queue', false);
277277

278278
/**
279-
* @const {boolean} Phaser.Core.Config#inputWindowEvents - Should Phaser listen for input events on the Window?
279+
* @const {boolean} Phaser.Core.Config#inputWindowEvents - Should Phaser listen for input events on the Window? If you disable this, events like 'POINTER_UP_OUTSIDE' will no longer fire.
280280
*/
281281
this.inputWindowEvents = GetValue(config, 'input.windowEvents', true);
282282

src/core/typedefs/InputConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
* @property {integer} [activePointers=1] - The maximum number of touch pointers. See {@link Phaser.Input.InputManager#pointers}.
1010
* @property {number} [smoothFactor=0] - The smoothing factor to apply during Pointer movement. See {@link Phaser.Input.Pointer#smoothFactor}.
1111
* @property {boolean} [inputQueue=false] - Should Phaser use a queued input system for native DOM Events or not?
12+
* @property {boolean} [windowEvents=true] - Should Phaser listen for input events on the Window? If you disable this, events like 'POINTER_UP_OUTSIDE' will no longer fire.
1213
*/

src/input/mouse/MouseManager.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,6 @@ var MouseManager = new Class({
304304

305305
this.onMouseDown = function (event)
306306
{
307-
console.log('down');
308-
309307
if (autoFocus)
310308
{
311309
window.focus();
@@ -327,8 +325,6 @@ var MouseManager = new Class({
327325

328326
this.onMouseDownWindow = function (event)
329327
{
330-
console.log('window down');
331-
332328
if (event.defaultPrevented || !_this.enabled || !_this.manager)
333329
{
334330
// Do nothing if event already handled
@@ -337,8 +333,6 @@ var MouseManager = new Class({
337333

338334
if (event.target !== canvas)
339335
{
340-
console.log('window process');
341-
342336
// Only process the event if the target isn't the canvas
343337
_this.manager.queueMouseDown(event);
344338
}
@@ -457,8 +451,8 @@ var MouseManager = new Class({
457451

458452
if (window)
459453
{
460-
window.removeEventListener('mousedown', this.onMouseDown);
461-
window.removeEventListener('mouseup', this.onMouseUp);
454+
window.removeEventListener('mousedown', this.onMouseDownWindow);
455+
window.removeEventListener('mouseup', this.onMouseUpWindow);
462456
}
463457

464458
if (Features.pointerLock)

src/input/touch/TouchManager.js

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ var TouchManager = new Class({
8383
*/
8484
this.onTouchStart = NOOP;
8585

86+
/**
87+
* The Touch Start event handler function specifically for events on the Window.
88+
* Initially empty and bound in the `startListeners` method.
89+
*
90+
* @name Phaser.Input.Touch.TouchManager#onTouchStartWindow
91+
* @type {function}
92+
* @since 3.16.3
93+
*/
94+
this.onTouchStartWindow = NOOP;
95+
8696
/**
8797
* The Touch Move event handler function.
8898
* Initially empty and bound in the `startListeners` method.
@@ -103,6 +113,16 @@ var TouchManager = new Class({
103113
*/
104114
this.onTouchEnd = NOOP;
105115

116+
/**
117+
* The Touch End event handler function specifically for events on the Window.
118+
* Initially empty and bound in the `startListeners` method.
119+
*
120+
* @name Phaser.Input.Touch.TouchManager#onTouchEndWindow
121+
* @type {function}
122+
* @since 3.16.3
123+
*/
124+
this.onTouchEndWindow = NOOP;
125+
106126
/**
107127
* The Touch Cancel event handler function.
108128
* Initially empty and bound in the `startListeners` method.
@@ -199,6 +219,21 @@ var TouchManager = new Class({
199219
}
200220
};
201221

222+
this.onTouchStartWindow = function (event)
223+
{
224+
if (event.defaultPrevented || !_this.enabled || !_this.manager)
225+
{
226+
// Do nothing if event already handled
227+
return;
228+
}
229+
230+
if (event.target !== canvas)
231+
{
232+
// Only process the event if the target isn't the canvas
233+
_this.manager.queueTouchStart(event);
234+
}
235+
};
236+
202237
this.onTouchMove = function (event)
203238
{
204239
if (event.defaultPrevented || !_this.enabled || !_this.manager)
@@ -231,6 +266,21 @@ var TouchManager = new Class({
231266
}
232267
};
233268

269+
this.onTouchEndWindow = function (event)
270+
{
271+
if (event.defaultPrevented || !_this.enabled || !_this.manager)
272+
{
273+
// Do nothing if event already handled
274+
return;
275+
}
276+
277+
if (event.target !== canvas)
278+
{
279+
// Only process the event if the target isn't the canvas
280+
_this.manager.queueTouchEnd(event);
281+
}
282+
};
283+
234284
this.onTouchCancel = function (event)
235285
{
236286
if (event.defaultPrevented || !_this.enabled || !_this.manager)
@@ -286,10 +336,10 @@ var TouchManager = new Class({
286336
target.addEventListener('touchover', this.onTouchOver, (this.capture) ? nonPassive : passive);
287337
target.addEventListener('touchout', this.onTouchOut, (this.capture) ? nonPassive : passive);
288338

289-
if (window)
339+
if (window && this.manager.game.config.inputWindowEvents)
290340
{
291-
window.addEventListener('touchstart', this.onTouchStart, nonPassive);
292-
window.addEventListener('touchend', this.onTouchEnd, nonPassive);
341+
window.addEventListener('touchstart', this.onTouchStartWindow, nonPassive);
342+
window.addEventListener('touchend', this.onTouchEndWindow, nonPassive);
293343
}
294344

295345
this.enabled = true;
@@ -315,8 +365,8 @@ var TouchManager = new Class({
315365

316366
if (window)
317367
{
318-
window.removeEventListener('touchstart', this.onTouchStart);
319-
window.removeEventListener('touchend', this.onTouchEnd);
368+
window.removeEventListener('touchstart', this.onTouchStartWindow);
369+
window.removeEventListener('touchend', this.onTouchEndWindow);
320370
}
321371
},
322372

0 commit comments

Comments
 (0)