Skip to content

Commit dd9e7e6

Browse files
committed
Pointer.dirty is a new boolean that is set by the InputHandler. It tells the Pointer to re-check all interactive objects it may be over on the next update, regardless if it has moved position or not. This helps solve issues where you may have a Button that on click generates a pop-up window that now obscures the Button (thanks @jflowers45 phaserjs#882)
1 parent b4ba795 commit dd9e7e6

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Version 2.1.0 - "Cairhien" - -in development-
9292
* Device.node and Device.nodeWebKit are two new properties (thanks @videlais #1129)
9393
* P2.PointProxy.mx and my values are get and set in meters with no pixel conversion taking place.
9494
* P2.InversePointProxy.mx and my values are get and set in meters with no pixel conversion taking place.
95+
* Pointer.dirty is a new boolean that is set by the InputHandler. It tells the Pointer to re-check all interactive objects it may be over on the next update, regardless if it has moved position or not. This helps solve issues where you may have a Button that on click generates a pop-up window that now obscures the Button (thanks @jflowers45 #882)
9596

9697
### Updates
9798

src/input/InputHandler.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ Phaser.InputHandler.prototype = {
832832
return;
833833
}
834834

835-
if (this._pointerData[pointer.id].isOver === false)
835+
if (this._pointerData[pointer.id].isOver === false || pointer.dirty)
836836
{
837837
this._pointerData[pointer.id].isOver = true;
838838
this._pointerData[pointer.id].isOut = false;
@@ -915,6 +915,9 @@ Phaser.InputHandler.prototype = {
915915
this.sprite.events.onInputDown.dispatch(this.sprite, pointer);
916916
}
917917

918+
// It's possible the onInputDown event created a new Sprite that is on-top of this one, so we ought to force a Pointer update
919+
pointer.dirty = true;
920+
918921
// Start drag
919922
if (this.draggable && this.isDragged === false)
920923
{
@@ -979,6 +982,9 @@ Phaser.InputHandler.prototype = {
979982
}
980983
}
981984

985+
// It's possible the onInputUp event created a new Sprite that is on-top of this one, so we ought to force a Pointer update
986+
pointer.dirty = true;
987+
982988
// Stop drag
983989
if (this.draggable && this.isDragged && this._draggedPointerID === pointer.id)
984990
{

src/input/Pointer.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ Phaser.Pointer = function (game, id) {
217217
*/
218218
this.active = false;
219219

220+
/**
221+
* @property {boolean} dirty - A dirty pointer needs to re-poll any interactive objects it may have been over, regardless if it has moved or not.
222+
* @default
223+
*/
224+
this.dirty = false;
225+
220226
/**
221227
* @property {Phaser.Point} position - A Phaser.Point object containing the current x/y values of the pointer on the display.
222228
*/
@@ -273,6 +279,7 @@ Phaser.Pointer.prototype = {
273279
this.withinGame = true;
274280
this.isDown = true;
275281
this.isUp = false;
282+
this.dirty = false;
276283

277284
// Work out how long it has been since the last click
278285
this.msSinceLastClick = this.game.time.now - this.timeDown;
@@ -319,6 +326,17 @@ Phaser.Pointer.prototype = {
319326

320327
if (this.active)
321328
{
329+
// Force a check?
330+
if (this.dirty)
331+
{
332+
if (this.game.input.interactiveItems.total > 0)
333+
{
334+
this.processInteractiveObjects(true);
335+
}
336+
337+
this.dirty = false;
338+
}
339+
322340
if (this._holdSent === false && this.duration >= this.game.input.holdRate)
323341
{
324342
if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers === 0))
@@ -497,7 +515,6 @@ Phaser.Pointer.prototype = {
497515
while (currentNode !== null);
498516

499517
// Now we know the top-most item (if any) we can process it
500-
501518
if (this._highestRenderObject === null)
502519
{
503520
// The pointer isn't currently over anything, check if we've got a lingering previous target
@@ -666,6 +683,7 @@ Phaser.Pointer.prototype = {
666683

667684
this.pointerId = null;
668685
this.identifier = null;
686+
this.dirty = false;
669687
this.isDown = false;
670688
this.isUp = true;
671689
this.totalTouches = 0;

0 commit comments

Comments
 (0)