From dd9e7e6297a6b01d91350a2d27f4bdf70147044a Mon Sep 17 00:00:00 2001 From: photonstorm Date: Fri, 29 Aug 2014 00:47:49 +0100 Subject: [PATCH] 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) --- README.md | 1 + src/input/InputHandler.js | 8 +++++++- src/input/Pointer.js | 20 +++++++++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4c806e170..231f93850 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,7 @@ Version 2.1.0 - "Cairhien" - -in development- * Device.node and Device.nodeWebKit are two new properties (thanks @videlais #1129) * P2.PointProxy.mx and my values are get and set in meters with no pixel conversion taking place. * P2.InversePointProxy.mx and my values are get and set in meters with no pixel conversion taking place. +* 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) ### Updates diff --git a/src/input/InputHandler.js b/src/input/InputHandler.js index 2187dfe9f..f853e99d1 100644 --- a/src/input/InputHandler.js +++ b/src/input/InputHandler.js @@ -832,7 +832,7 @@ Phaser.InputHandler.prototype = { return; } - if (this._pointerData[pointer.id].isOver === false) + if (this._pointerData[pointer.id].isOver === false || pointer.dirty) { this._pointerData[pointer.id].isOver = true; this._pointerData[pointer.id].isOut = false; @@ -915,6 +915,9 @@ Phaser.InputHandler.prototype = { this.sprite.events.onInputDown.dispatch(this.sprite, pointer); } + // 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 + pointer.dirty = true; + // Start drag if (this.draggable && this.isDragged === false) { @@ -979,6 +982,9 @@ Phaser.InputHandler.prototype = { } } + // 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 + pointer.dirty = true; + // Stop drag if (this.draggable && this.isDragged && this._draggedPointerID === pointer.id) { diff --git a/src/input/Pointer.js b/src/input/Pointer.js index 5bd9b8bfa..67db46041 100644 --- a/src/input/Pointer.js +++ b/src/input/Pointer.js @@ -217,6 +217,12 @@ Phaser.Pointer = function (game, id) { */ this.active = false; + /** + * @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. + * @default + */ + this.dirty = false; + /** * @property {Phaser.Point} position - A Phaser.Point object containing the current x/y values of the pointer on the display. */ @@ -273,6 +279,7 @@ Phaser.Pointer.prototype = { this.withinGame = true; this.isDown = true; this.isUp = false; + this.dirty = false; // Work out how long it has been since the last click this.msSinceLastClick = this.game.time.now - this.timeDown; @@ -319,6 +326,17 @@ Phaser.Pointer.prototype = { if (this.active) { + // Force a check? + if (this.dirty) + { + if (this.game.input.interactiveItems.total > 0) + { + this.processInteractiveObjects(true); + } + + this.dirty = false; + } + if (this._holdSent === false && this.duration >= this.game.input.holdRate) { 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 = { while (currentNode !== null); // Now we know the top-most item (if any) we can process it - if (this._highestRenderObject === null) { // The pointer isn't currently over anything, check if we've got a lingering previous target @@ -666,6 +683,7 @@ Phaser.Pointer.prototype = { this.pointerId = null; this.identifier = null; + this.dirty = false; this.isDown = false; this.isUp = true; this.totalTouches = 0;