Skip to content

Commit cf74eaa

Browse files
committed
MSPointer now checks the pointerType property of the DOM event and if it matches 'mouse' it will update Input.mousePointer, rather than Input.pointer1 (or whatever the next free Pointer was).
1 parent 7ffbeb8 commit cf74eaa

5 files changed

Lines changed: 124 additions & 75 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ Version 2.4 - "Katar" - in dev
250250
* Phaser.DeviceButton.altKey is a boolean that holds if the alt key was held down or not during the last button event.
251251
* Phaser.DeviceButton.ctrlKey is a boolean that holds if the control key was held down or not during the last button event.
252252
* Phaser.GamepadButton has been removed and now uses DeviceButton instead. Three internal API changes took place: `processButtonDown` is renamed to `start`, `processButtonUp` is renamed to `stop` and `processButtonFloat` is renamed to `padFloat`. If you extended GamepadButton in your own code you need to replace it with DeviceButton.
253+
* MSPointer now checks the `pointerType` property of the DOM event and if it matches 'mouse' it will update `Input.mousePointer`, rather than `Input.pointer1` (or whatever the next free Pointer was).
253254

254255
### p2.js Upgraded to version 0.7.0
255256

src/input/Input.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ Phaser.Input = function (game) {
228228
this.mouse = null;
229229

230230
/**
231-
* @property {Phaser.Keyboard} keyboard - The Keyboard Input manager.
231+
* The Keyboard Input manager.
232+
*
233+
* @property {Phaser.Keyboard} keyboard
232234
*/
233235
this.keyboard = null;
234236

@@ -253,38 +255,48 @@ Phaser.Input = function (game) {
253255
this.mspointer = null;
254256

255257
/**
256-
* @property {Phaser.Gamepad} gamepad - The Gamepad Input manager.
258+
* The Gamepad Input manager.
259+
*
260+
* @property {Phaser.Gamepad} gamepad
257261
*/
258262
this.gamepad = null;
259263

260264
/**
261-
* @property {boolean} resetLocked - If the Input Manager has been reset locked then all calls made to InputManager.reset, such as from a State change, are ignored.
265+
* If the Input Manager has been reset locked then all calls made to InputManager.reset,
266+
* such as from a State change, are ignored.
267+
* @property {boolean} resetLocked
262268
* @default
263269
*/
264270
this.resetLocked = false;
265271

266272
/**
267-
* @property {Phaser.Signal} onDown - A Signal that is dispatched each time a pointer is pressed down.
273+
* A Signal that is dispatched each time a pointer is pressed down.
274+
* @property {Phaser.Signal} onDown
268275
*/
269276
this.onDown = null;
270277

271278
/**
272-
* @property {Phaser.Signal} onUp - A Signal that is dispatched each time a pointer is released.
279+
* A Signal that is dispatched each time a pointer is released.
280+
* @property {Phaser.Signal} onUp
273281
*/
274282
this.onUp = null;
275283

276284
/**
277-
* @property {Phaser.Signal} onTap - A Signal that is dispatched each time a pointer is tapped.
285+
* A Signal that is dispatched each time a pointer is tapped.
286+
* @property {Phaser.Signal} onTap
278287
*/
279288
this.onTap = null;
280289

281290
/**
282-
* @property {Phaser.Signal} onHold - A Signal that is dispatched each time a pointer is held down.
291+
* A Signal that is dispatched each time a pointer is held down.
292+
* @property {Phaser.Signal} onHold
283293
*/
284294
this.onHold = null;
285295

286296
/**
287-
* @property {number} minPriorityID - You can tell all Pointers to ignore any object with a priorityID lower than the minPriorityID. Useful when stacking UI layers. Set to zero to disable.
297+
* You can tell all Pointers to ignore any Game Object with a `priorityID` lower than this value.
298+
* This is useful when stacking UI layers. Set to zero to disable.
299+
* @property {number} minPriorityID
288300
* @default
289301
*/
290302
this.minPriorityID = 0;

src/input/MSPointer.js

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
/**
88
* The MSPointer class handles Microsoft touch interactions with the game and the resulting Pointer objects.
99
*
10-
* It will work only in Internet Explorer 10 and Windows Store or Windows Phone 8 apps using JavaScript.
10+
* It will work only in Internet Explorer 10+ and Windows Store or Windows Phone 8 apps using JavaScript.
1111
* http://msdn.microsoft.com/en-us/library/ie/hh673557(v=vs.85).aspx
1212
*
1313
* You should not normally access this class directly, but instead use a Phaser.Pointer object which
1414
* normalises all game input for you including accurate button handling.
1515
*
16+
* Please note that at the current time of writing Phaser does not yet support chorded button interactions:
17+
* http://www.w3.org/TR/pointerevents/#chorded-button-interactions
18+
*
1619
* @class Phaser.MSPointer
1720
* @constructor
1821
* @param {Phaser.Game} game - A reference to the currently running game.
@@ -24,6 +27,12 @@ Phaser.MSPointer = function (game) {
2427
*/
2528
this.game = game;
2629

30+
/**
31+
* @property {Phaser.Input} input - A reference to the Phaser Input Manager.
32+
* @protected
33+
*/
34+
this.input = game.input;
35+
2736
/**
2837
* @property {object} callbackContext - The context under which callbacks are called (defaults to game).
2938
*/
@@ -122,17 +131,19 @@ Phaser.MSPointer.prototype = {
122131
return _this.onPointerUp(event);
123132
};
124133

125-
this.game.canvas.addEventListener('MSPointerDown', this._onMSPointerDown, false);
126-
this.game.canvas.addEventListener('MSPointerMove', this._onMSPointerMove, false);
127-
this.game.canvas.addEventListener('MSPointerUp', this._onMSPointerUp, false);
134+
var canvas = this.game.canvas;
135+
136+
canvas.addEventListener('MSPointerDown', this._onMSPointerDown, false);
137+
canvas.addEventListener('MSPointerMove', this._onMSPointerMove, false);
138+
canvas.addEventListener('MSPointerUp', this._onMSPointerUp, false);
128139

129140
// IE11+ uses non-prefix events
130-
this.game.canvas.addEventListener('pointerDown', this._onMSPointerDown, false);
131-
this.game.canvas.addEventListener('pointerMove', this._onMSPointerMove, false);
132-
this.game.canvas.addEventListener('pointerUp', this._onMSPointerUp, false);
141+
canvas.addEventListener('pointerDown', this._onMSPointerDown, false);
142+
canvas.addEventListener('pointerMove', this._onMSPointerMove, false);
143+
canvas.addEventListener('pointerUp', this._onMSPointerUp, false);
133144

134-
this.game.canvas.style['-ms-content-zooming'] = 'none';
135-
this.game.canvas.style['-ms-touch-action'] = 'none';
145+
canvas.style['-ms-content-zooming'] = 'none';
146+
canvas.style['-ms-touch-action'] = 'none';
136147
}
137148

138149
},
@@ -145,6 +156,8 @@ Phaser.MSPointer.prototype = {
145156
*/
146157
onPointerDown: function (event) {
147158

159+
console.log('onPointerDown', event.buttons, event.button);
160+
148161
this.event = event;
149162

150163
if (this.capture)
@@ -157,14 +170,21 @@ Phaser.MSPointer.prototype = {
157170
this.pointerDownCallback.call(this.callbackContext, event);
158171
}
159172

160-
if (!this.game.input.enabled || !this.enabled)
173+
if (!this.input.enabled || !this.enabled)
161174
{
162175
return;
163176
}
164177

165178
event.identifier = event.pointerId;
166179

167-
this.game.input.startPointer(event);
180+
if (event.pointerType === 'mouse' || event.pointerType === 0x00000004)
181+
{
182+
this.input.mousePointer.start(event);
183+
}
184+
else
185+
{
186+
this.input.startPointer(event);
187+
}
168188

169189
},
170190

@@ -187,14 +207,21 @@ Phaser.MSPointer.prototype = {
187207
this.pointerMoveCallback.call(this.callbackContext, event);
188208
}
189209

190-
if (!this.game.input.enabled || !this.enabled)
210+
if (!this.input.enabled || !this.enabled)
191211
{
192212
return;
193213
}
194214

195215
event.identifier = event.pointerId;
196216

197-
this.game.input.updatePointer(event);
217+
if (event.pointerType === 'mouse' || event.pointerType === 0x00000004)
218+
{
219+
this.input.mousePointer.move(event);
220+
}
221+
else
222+
{
223+
this.input.updatePointer(event);
224+
}
198225

199226
},
200227

@@ -205,6 +232,8 @@ Phaser.MSPointer.prototype = {
205232
*/
206233
onPointerUp: function (event) {
207234

235+
console.log('onPointerUp', event.buttons, event.button);
236+
208237
this.event = event;
209238

210239
if (this.capture)
@@ -217,14 +246,21 @@ Phaser.MSPointer.prototype = {
217246
this.pointerUpCallback.call(this.callbackContext, event);
218247
}
219248

220-
if (!this.game.input.enabled || !this.enabled)
249+
if (!this.input.enabled || !this.enabled)
221250
{
222251
return;
223252
}
224253

225254
event.identifier = event.pointerId;
226255

227-
this.game.input.stopPointer(event);
256+
if (event.pointerType === 'mouse' || event.pointerType === 0x00000004)
257+
{
258+
this.input.mousePointer.stop(event);
259+
}
260+
else
261+
{
262+
this.input.stopPointer(event);
263+
}
228264

229265
},
230266

@@ -234,13 +270,15 @@ Phaser.MSPointer.prototype = {
234270
*/
235271
stop: function () {
236272

237-
this.game.canvas.removeEventListener('MSPointerDown', this._onMSPointerDown);
238-
this.game.canvas.removeEventListener('MSPointerMove', this._onMSPointerMove);
239-
this.game.canvas.removeEventListener('MSPointerUp', this._onMSPointerUp);
273+
var canvas = this.game.canvas;
274+
275+
canvas.removeEventListener('MSPointerDown', this._onMSPointerDown);
276+
canvas.removeEventListener('MSPointerMove', this._onMSPointerMove);
277+
canvas.removeEventListener('MSPointerUp', this._onMSPointerUp);
240278

241-
this.game.canvas.removeEventListener('pointerDown', this._onMSPointerDown);
242-
this.game.canvas.removeEventListener('pointerMove', this._onMSPointerMove);
243-
this.game.canvas.removeEventListener('pointerUp', this._onMSPointerUp);
279+
canvas.removeEventListener('pointerDown', this._onMSPointerDown);
280+
canvas.removeEventListener('pointerMove', this._onMSPointerMove);
281+
canvas.removeEventListener('pointerUp', this._onMSPointerUp);
244282

245283
}
246284

0 commit comments

Comments
 (0)