Skip to content

Commit 31e5202

Browse files
committed
Fixes phaserjs#2062 and forward-support for pointer modes
Impact: - *none for touch devices* - *low* / 'expected behavior' for mouse devices Adds a PointerMode enumeration value for better simple input discrimination in the future. The added Button#justReleasedPreventsOver controls if a just-release event on a pointer prevents it from being able to trigger an over event. The default value is PointerMode.CONTACT which means this 'release guard' applies only to touch inputs. It should fix phaserjs#2062 as Mouse (PointerMode.CURSOR) input is not caught in the default. Also expands Button#forceOut to accept a PointerMode value such that it can be controlled per-input mode. This is a configurable partial revert of a possibly rogue commit in 2.1.3 and the behavior persists through 2.4.3.
1 parent bae732c commit 31e5202

3 files changed

Lines changed: 56 additions & 7 deletions

File tree

src/gameobjects/Button.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,20 @@ Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame,
166166
/**
167167
* If true then onOver events (such as onOverSound) will only be triggered if the Pointer object causing them was the Mouse Pointer.
168168
* The frame will still be changed as applicable.
169+
*
169170
* @property {boolean} onOverMouseOnly
170171
* @default
171172
*/
172173
this.onOverMouseOnly = false;
174+
175+
/**
176+
* Suppresse the over event if a pointer was just released and it matches the given {@link Phaser.PointerModer pointer mode bitmask}.
177+
*
178+
* This behavior was introduced in Phaser 2.3.1; this property is a soft-revert of the change.
179+
*
180+
* @property {Phaser.PointerMode?} justReleasedPreventsOver=ACTIVE_CURSOR
181+
*/
182+
this.justReleasedPreventsOver = Phaser.PointerMode.TOUCH;
173183

174184
/**
175185
* When true the the texture frame will not be automatically switched on up/down/over/out events.
@@ -180,7 +190,10 @@ Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame,
180190

181191
/**
182192
* When the Button is touched / clicked and then released you can force it to enter a state of "out" instead of "up".
183-
* @property {boolean} forceOut
193+
*
194+
* This can also accept a {@link Phaser.PointerModer pointer mode bitmask} for more refined control.
195+
*
196+
* @property {boolean|Phaser.PointerMode} forceOut=false
184197
* @default
185198
*/
186199
this.forceOut = false;
@@ -472,9 +485,10 @@ Phaser.Button.prototype.setUpSound = function (sound, marker) {
472485
*/
473486
Phaser.Button.prototype.onInputOverHandler = function (sprite, pointer) {
474487

475-
// If the Pointer was only just released then we don't fire an over event
476-
if (pointer.justReleased())
488+
if (pointer.justReleased() &&
489+
(this.justReleasedPreventsOver & pointer.pointerMode) === pointer.pointerMode)
477490
{
491+
// If the Pointer was only just released then we don't fire an over event
478492
return;
479493
}
480494

@@ -557,7 +571,7 @@ Phaser.Button.prototype.onInputUpHandler = function (sprite, pointer, isOver) {
557571
return;
558572
}
559573

560-
if (this.forceOut)
574+
if (this.forceOut === true || (this.forceOut & pointer.pointerMode) === pointer.pointerMode)
561575
{
562576
this.changeStateFrame(STATE_OUT);
563577
}

src/input/Input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ Phaser.Input.prototype = {
374374
*/
375375
boot: function () {
376376

377-
this.mousePointer = new Phaser.Pointer(this.game, 0);
377+
this.mousePointer = new Phaser.Pointer(this.game, 0, Phaser.PointerMode.CURSOR);
378378
this.addPointer();
379379
this.addPointer();
380380

@@ -517,7 +517,7 @@ Phaser.Input.prototype = {
517517
}
518518

519519
var id = this.pointers.length + 1;
520-
var pointer = new Phaser.Pointer(this.game, id);
520+
var pointer = new Phaser.Pointer(this.game, id, Phaser.PointerMode.TOUCH);
521521

522522
this.pointers.push(pointer);
523523
this['pointer' + id] = pointer;

src/input/Pointer.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
* @constructor
1212
* @param {Phaser.Game} game - A reference to the currently running game.
1313
* @param {number} id - The ID of the Pointer object within the game. Each game can have up to 10 active pointers.
14+
* @param {Phaser.PointerMode} pointerMode=(CURSOR|CONTACT) - The operational mode of this pointer, eg. CURSOR or TOUCH.
1415
*/
15-
Phaser.Pointer = function (game, id) {
16+
Phaser.Pointer = function (game, id, pointerMode) {
1617

1718
/**
1819
* @property {Phaser.Game} game - A reference to the currently running game.
@@ -48,6 +49,11 @@ Phaser.Pointer = function (game, id) {
4849
*/
4950
this.pointerId = null;
5051

52+
/**
53+
* @property {Phaser.PointerMode} pointerMode - The operational mode of this pointer.
54+
*/
55+
this.pointerMode = pointerMode || (Phaser.PointerMode.CURSOR | Phaser.PointerMode.CONTACT);
56+
5157
/**
5258
* @property {any} target - The target property of the Pointer as set by the DOM event when this Pointer is started.
5359
* @default
@@ -1189,3 +1195,32 @@ Object.defineProperty(Phaser.Pointer.prototype, "worldY", {
11891195
}
11901196

11911197
});
1198+
1199+
/**
1200+
* Enumeration categorizing operational modes of pointers.
1201+
*
1202+
* PointerType values represent valid bitmasks.
1203+
* For example, a value representing both Mouse and Touch devices
1204+
* can be expressed as `PointerMode.CURSOR | PointerMode.CONTACT`.
1205+
*
1206+
* Values may be added for future mode categorizations.
1207+
* @class Phaser.PointerMode
1208+
*/
1209+
Phaser.PointerMode = {
1210+
1211+
/**
1212+
* A 'CURSOR' is a pointer with a *passive cursor* such as a mouse, touchpad, watcom stylus, or even TV-control arrow-pad.
1213+
*
1214+
* It has the property that a cursor is passively moved without activating the input.
1215+
* This currently corresponds with {@link Phaser.Pointer#isMouse} property.
1216+
* @constant
1217+
*/
1218+
CURSOR: 1 << 0,
1219+
1220+
/**
1221+
* A 'CONTACT' pointer has an *active cursor* that only tracks movement when actived; notably this is a touch-style input.
1222+
* @constant
1223+
*/
1224+
CONTACT: 1 << 1
1225+
1226+
};

0 commit comments

Comments
 (0)