Skip to content

Commit

Permalink
The InputManager.onTouchMove method will now check if the changed t…
Browse files Browse the repository at this point in the history
…ouch is over the canvas, or not, via the DOM `elementFromPoint` function. This means if the touch leaves the canvas, it will now trigger the `GAME_OUT` and `GAME_OVER` events, where-as before this would only happen for a Mouse. If the touch isn't over the canvas, no Pointer touch move happens, just like with the mouse. Fix #5592
  • Loading branch information
photonstorm committed Dec 1, 2021
1 parent d36c817 commit 91f72f7
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions src/input/InputManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,18 @@ var InputManager = new Class({
*/
boot: function ()
{
this.canvas = this.game.canvas;
var game = this.game;
var events = game.events;

this.scaleManager = this.game.scale;
this.canvas = game.canvas;

this.scaleManager = game.scale;

this.events.emit(Events.MANAGER_BOOT);

this.game.events.on(GameEvents.PRE_RENDER, this.preRender, this);
events.on(GameEvents.PRE_RENDER, this.preRender, this);

this.game.events.once(GameEvents.DESTROY, this.destroy, this);
events.once(GameEvents.DESTROY, this.destroy, this);
},

/**
Expand Down Expand Up @@ -605,19 +608,32 @@ var InputManager = new Class({
{
var changedTouch = event.changedTouches[c];

// document.elementFromPoint(0,0)

for (var i = 1; i < this.pointersTotal; i++)
{
var pointer = pointers[i];

if (pointer.active && pointer.identifier === changedTouch.identifier)
{
pointer.touchmove(changedTouch, event);

this.activePointer = pointer;

changed.push(pointer);
var element = document.elementFromPoint(changedTouch.pageX, changedTouch.pageY);
var overCanvas = element === this.canvas;

if (!this.isOver && overCanvas)
{
this.setCanvasOver(event);
}
else if (this.isOver && !overCanvas)
{
this.setCanvasOut(event);
}

if (this.isOver)
{
pointer.touchmove(changedTouch, event);

this.activePointer = pointer;

changed.push(pointer);
}

break;
}
Expand Down

0 comments on commit 91f72f7

Please sign in to comment.