Skip to content

Commit 8dec371

Browse files
committed
MSPointer.capture allows you to optionally event.preventDefault the pointer events (was previously always on)
MSPointer.event now stores the most recent pointer event. MSPointer.pointerDownCallback, pointerMoveCallback and pointerUpCallback all allow you to set your own event based callbacks.
1 parent 336fdfa commit 8dec371

2 files changed

Lines changed: 67 additions & 3 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ Version 2.3.0 - "Tarabon" - in dev
6565
* `Physics.Arcade.isPaused` allows you to toggle Arcade Physics processing on and off. If `true` the `Body.preUpdate` method will be skipped, halting all motion for all bodies. Note that other methods such as `collide` will still work, so be careful not to call them on paused bodies.
6666
* `Arcade.Body.friction` allows you to have more fine-grained control over the amount of velocity passed between bodies on collision.
6767
* BitmapData.text will render the given string to the BitmapData, with optional font, color and shadow settings.
68+
* MSPointer.capture allows you to optionally event.preventDefault the pointer events (was previously always on)
69+
* MSPointer.event now stores the most recent pointer event.
70+
* MSPointer.pointerDownCallback, pointerMoveCallback and pointerUpCallback all allow you to set your own event based callbacks.
6871

6972
### Updates
7073

src/input/MSPointer.js

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,34 @@ Phaser.MSPointer = function (game) {
2626
*/
2727
this.callbackContext = this.game;
2828

29+
/**
30+
* @property {function} pointerDownCallback - A callback that can be fired on a MSPointerDown event.
31+
*/
32+
this.pointerDownCallback = null;
33+
34+
/**
35+
* @property {function} pointerMoveCallback - A callback that can be fired on a MSPointerMove event.
36+
*/
37+
this.pointerMoveCallback = null;
38+
39+
/**
40+
* @property {function} pointerUpCallback - A callback that can be fired on a MSPointerUp event.
41+
*/
42+
this.pointerUpCallback = null;
43+
44+
/**
45+
* @property {boolean} capture - If true the Pointer events will have event.preventDefault applied to them, if false they will propagate fully.
46+
*/
47+
this.capture = false;
48+
49+
/**
50+
* The browser MSPointer DOM event. Will be null if no event has ever been received.
51+
* Access this property only inside a Pointer event handler and do not keep references to it.
52+
* @property {MSPointerEvent|null} event
53+
* @default
54+
*/
55+
this.event = null;
56+
2957
/**
3058
* MSPointer input will only be processed if enabled.
3159
* @property {boolean} enabled
@@ -106,12 +134,23 @@ Phaser.MSPointer.prototype = {
106134
*/
107135
onPointerDown: function (event) {
108136

137+
this.event = event;
138+
139+
if (this.capture)
140+
{
141+
event.preventDefault();
142+
}
143+
144+
if (this.pointerDownCallback)
145+
{
146+
this.pointerDownCallback.call(this.callbackContext, event);
147+
}
148+
109149
if (!this.game.input.enabled || !this.enabled)
110150
{
111151
return;
112152
}
113153

114-
event.preventDefault();
115154
event.identifier = event.pointerId;
116155

117156
this.game.input.startPointer(event);
@@ -125,12 +164,23 @@ Phaser.MSPointer.prototype = {
125164
*/
126165
onPointerMove: function (event) {
127166

167+
this.event = event;
168+
169+
if (this.capture)
170+
{
171+
event.preventDefault();
172+
}
173+
174+
if (this.pointerMoveCallback)
175+
{
176+
this.pointerMoveCallback.call(this.callbackContext, event);
177+
}
178+
128179
if (!this.game.input.enabled || !this.enabled)
129180
{
130181
return;
131182
}
132183

133-
event.preventDefault();
134184
event.identifier = event.pointerId;
135185

136186
this.game.input.updatePointer(event);
@@ -144,12 +194,23 @@ Phaser.MSPointer.prototype = {
144194
*/
145195
onPointerUp: function (event) {
146196

197+
this.event = event;
198+
199+
if (this.capture)
200+
{
201+
event.preventDefault();
202+
}
203+
204+
if (this.pointerUpCallback)
205+
{
206+
this.pointerUpCallback.call(this.callbackContext, event);
207+
}
208+
147209
if (!this.game.input.enabled || !this.enabled)
148210
{
149211
return;
150212
}
151213

152-
event.preventDefault();
153214
event.identifier = event.pointerId;
154215

155216
this.game.input.stopPointer(event);

0 commit comments

Comments
 (0)