diff --git a/src/input/InputHandler.js b/src/input/InputHandler.js index 9abd0a9f..b562e7a6 100644 --- a/src/input/InputHandler.js +++ b/src/input/InputHandler.js @@ -49,6 +49,8 @@ Phaser.InputHandler = function (sprite) { */ this.consumePointerEvent = false; + this._tempPoint = new Phaser.Point; + }; Phaser.InputHandler.prototype = { @@ -102,7 +104,7 @@ Phaser.InputHandler.prototype = { this.enabled = true; // Create the signals the Input component will emit - if (this.sprite.events.onInputOver == null) + if (this.sprites.events && this.sprite.events.onInputOver == null) { this.sprite.events.onInputOver = new Phaser.Signal; this.sprite.events.onInputOut = new Phaser.Signal; @@ -318,12 +320,29 @@ Phaser.InputHandler.prototype = { */ checkPointerOver: function (pointer) { - if (this.enabled == false || this.sprite.visible == false) + if (this.enabled && this.sprite.visible) { - return false; + this.sprite.getLocalPosition(this._tempPoint, pointer.x, pointer.y); + + // Check against bounds + var width = this.sprite.texture.frame.width, + height = this.sprite.texture.frame.height, + x1 = -width * this.sprite.anchor.x, + y1; + + if(x > x1 && x < x1 + width) + { + y1 = -height * this.sprite.anchor.y; + + if(y > y1 && y < y1 + height) + { + return true; + } + } } else { + return false; } }, diff --git a/src/input/Pointer.js b/src/input/Pointer.js index b4252755..895e88f0 100644 --- a/src/input/Pointer.js +++ b/src/input/Pointer.js @@ -362,7 +362,7 @@ Phaser.Pointer.prototype = { // Work out which object is on the top this._highestRenderOrderID = -1; - this._highestRenderObject = -1; + this._highestRenderObject = null; this._highestInputPriorityID = -1; // Just run through the linked list @@ -372,9 +372,12 @@ Phaser.Pointer.prototype = { do { - if (currentNode['update']) + // If the object has a higher InputManager.PriorityID OR if the priority ID is the same as the current highest AND it has a higher renderOrderID, then set it to the top + if (currentNode.priorityID > this._highestInputPriorityID || (currentNode.priorityID == this._highestInputPriorityID && currentNode.sprite.renderOrderID > this._highestRenderOrderID) && currentNode.checkPointerOver(this)) { - currentNode.update(); + this._highestRenderOrderID = currentNode.sprite.renderOrderID; + this._highestInputPriorityID = currentNode.priorityID; + this._highestRenderObject = currentNode; } currentNode = currentNode.next; @@ -383,6 +386,7 @@ Phaser.Pointer.prototype = { } +/* for (var i = 0; i < this.game.input.totalTrackedObjects; i++) { if (this.game.input.inputObjects[i] && this.game.input.inputObjects[i].input && this.game.input.inputObjects[i].input.checkPointerOver(this)) @@ -396,13 +400,14 @@ Phaser.Pointer.prototype = { } } } +*/ - if (this._highestRenderObject == -1) + if (this._highestRenderObject == null) { - // The pointer isn't over anything, check if we've got a lingering previous target - if (this.targetObject !== null) + // The pointer isn't currently over anything, check if we've got a lingering previous target + if (this.targetObject) { - this.targetObject.input._pointerOutHandler(this); + this.targetObject._pointerOutHandler(this); this.targetObject = null; } } @@ -411,16 +416,16 @@ Phaser.Pointer.prototype = { if (this.targetObject == null) { // And now set the new one - this.targetObject = this.game.input.inputObjects[this._highestRenderObject]; - this.targetObject.input._pointerOverHandler(this); + this.targetObject = this._highestRenderObject; + this._highestRenderObject._pointerOverHandler(this); } else { // We've got a target from the last update - if (this.targetObject == this.game.input.inputObjects[this._highestRenderObject]) + if (this.targetObject == this._highestRenderObject) { // Same target as before, so update it - if (this.targetObject.input.update(this) == false) + if (this._highestRenderObject.update(this) == false) { this.targetObject = null; } @@ -428,11 +433,11 @@ Phaser.Pointer.prototype = { else { // The target has changed, so tell the old one we've left it - this.targetObject.input._pointerOutHandler(this); + this.targetObject._pointerOutHandler(this); // And now set the new one - this.targetObject = this.game.input.inputObjects[this._highestRenderObject]; - this.targetObject.input._pointerOverHandler(this); + this.targetObject = this._highestRenderObject; + this.targetObject._pointerOverHandler(this); } } } @@ -506,17 +511,22 @@ Phaser.Pointer.prototype = { this.game.input.currentPointers--; } - for (var i = 0; i < this.game.input.totalTrackedObjects; i++) + if (this.game.input.interactiveItems.next) { - if (this.game.input.inputObjects[i] && this.game.input.inputObjects[i].input && this.game.input.inputObjects[i].input.enabled) + var currentNode = this.game.input.interactiveItems.next; + + do { - this.game.input.inputObjects[i].input._releasedHandler(this); + currentNode._releasedHandler(this); + + currentNode = currentNode.next; } + while (currentNode != this.game.input.interactiveItems.next) } if (this.targetObject) { - this.targetObject.input._releasedHandler(this); + this.targetObject._releasedHandler(this); } this.targetObject = null; @@ -532,7 +542,7 @@ Phaser.Pointer.prototype = { */ justPressed: function (duration) { - if (typeof duration === "undefined") { duration = this.game.input.justPressedRate; } + duration = duration || this.game.input.justPressedRate; return (this.isDown === true && (this.timeDown + duration) > this.game.time.now); @@ -546,7 +556,7 @@ Phaser.Pointer.prototype = { */ justReleased: function (duration) { - if (typeof duration === "undefined") { duration = this.game.input.justReleasedRate; } + duration = duration || this.game.input.justReleasedRate; return (this.isUp === true && (this.timeUp + duration) > this.game.time.now); @@ -571,9 +581,9 @@ Phaser.Pointer.prototype = { this._history.length = 0; this._stateReset = true; - if (this.targetObject && this.targetObject.input) + if (this.targetObject) { - this.targetObject.input._releasedHandler(this); + this.targetObject._releasedHandler(this); } this.targetObject = null;