Skip to content

Commit 9cdcdc7

Browse files
committed
Device.touch checks if window.navigator.maxTouchPoints is >= 1 rather than > 1, which now allows touch events to work properly in Chrome mobile emulation.
1 parent 5bd231d commit 9cdcdc7

4 files changed

Lines changed: 14 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Version 2.3.0 - "Tarabon" - in dev
6868
* MSPointer.capture allows you to optionally event.preventDefault the pointer events (was previously always on)
6969
* MSPointer.event now stores the most recent pointer event.
7070
* MSPointer.pointerDownCallback, pointerMoveCallback and pointerUpCallback all allow you to set your own event based callbacks.
71+
* MSPointer.button now records which button was pressed down (if any)
7172

7273
### Updates
7374

@@ -83,6 +84,7 @@ Version 2.3.0 - "Tarabon" - in dev
8384
* TilemapLayer.getTiles now returns a copy of the Tiles found by the method, rather than references to the original Tile objects, so you're free to modify them without corrupting the source (thanks @Leekao #1585)
8485
* Sprite.events.onDragStart has 2 new parameters `x` and `y` which is the position of the Sprite before the drag was started. The full list of parameters is: `(sprite, pointer, x, y)`. This allows you to retain the position of the Sprite prior to dragging should `dragFromCenter` have been enabled (thanks @vulvulune #1583)
8586
* Body.reset now resets the Body.speed value to zero.
87+
* Device.touch checks if `window.navigator.maxTouchPoints` is `>= 1` rather than > 1, which now allows touch events to work properly in Chrome mobile emulation.
8688

8789
### Bug Fixes
8890

src/input/MSPointer.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ Phaser.MSPointer = function (game) {
4646
*/
4747
this.capture = false;
4848

49+
/**
50+
* @property {number} button- The type of click, either: Phaser.Mouse.NO_BUTTON, Phaser.Mouse.LEFT_BUTTON, Phaser.Mouse.MIDDLE_BUTTON or Phaser.Mouse.RIGHT_BUTTON.
51+
* @default
52+
*/
53+
this.button = -1;
54+
4955
/**
5056
* The browser MSPointer DOM event. Will be null if no event has ever been received.
5157
* Access this property only inside a Pointer event handler and do not keep references to it.
@@ -141,6 +147,8 @@ Phaser.MSPointer.prototype = {
141147
event.preventDefault();
142148
}
143149

150+
this.button = event.button;
151+
144152
if (this.pointerDownCallback)
145153
{
146154
this.pointerDownCallback.call(this.callbackContext, event);
@@ -201,6 +209,8 @@ Phaser.MSPointer.prototype = {
201209
event.preventDefault();
202210
}
203211

212+
this.button = Phaser.Mouse.NO_BUTTON;
213+
204214
if (this.pointerUpCallback)
205215
{
206216
this.pointerUpCallback.call(this.callbackContext, event);

src/input/Mouse.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ Phaser.Mouse.prototype = {
249249
}
250250

251251
var wheelEvent = this.game.device.wheelEvent;
252+
252253
if (wheelEvent)
253254
{
254255
this.game.canvas.addEventListener(wheelEvent, this._onMouseWheel, true);

src/system/Device.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,7 @@ Phaser.Device._initialize = function () {
686686
*/
687687
function _checkInput () {
688688

689-
if ('ontouchstart' in document.documentElement ||
690-
(window.navigator.maxTouchPoints && window.navigator.maxTouchPoints > 1))
689+
if ('ontouchstart' in document.documentElement || (window.navigator.maxTouchPoints && window.navigator.maxTouchPoints >= 1))
691690
{
692691
device.touch = true;
693692
}

0 commit comments

Comments
 (0)