From c9656e48debf43bf3544f9dcaa27d4dab82db6f1 Mon Sep 17 00:00:00 2001 From: photonstorm Date: Mon, 19 May 2014 13:11:58 +0100 Subject: [PATCH] Group.hasProperty fixed to not use hasOwnProperty, but a series of `in` checks (thanks @mgiuffrida for the idea, #829) --- README.md | 1 + src/core/Group.js | 10 +++++----- src/input/Pointer.js | 6 ++++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index bca1db0f6f..109e59a7f0 100644 --- a/README.md +++ b/README.md @@ -141,6 +141,7 @@ Version 2.0.5 - "Tanchico" - in development * If an object was drag enabled with bringToTop, the onDragStop event wouldn't fire until the mouse was next moved (thanks @alpera, fix #813) * RetroFont.text would throw WebGL errors due to an issue with Pixi.RenderTexture. Fixed in Phaser and submitted code to Pixi. * RenderTexture.resize would throw WebGL errors due to an issue with Pixi.RenderTexture. Fixed in Phaser and submitted code to Pixi. +* Group.hasProperty fixed to not use hasOwnProperty, but a series of `in` checks (thanks @mgiuffrida for the idea, #829) ### To Do diff --git a/src/core/Group.js b/src/core/Group.js index ffcaf52e02..abbe3a78de 100644 --- a/src/core/Group.js +++ b/src/core/Group.js @@ -643,19 +643,19 @@ Phaser.Group.prototype.hasProperty = function (child, key) { var len = key.length; - if (len === 1 && child.hasOwnProperty(key[0])) + if (len === 1 && key[0] in child) { return true; } - else if (len === 2 && child.hasOwnProperty(key[0]) && child[key[0]].hasOwnProperty(key[1])) + else if (len === 2 && key[0] in child && key[1] in child[key[0]]) { return true; } - else if (len === 3 && child.hasOwnProperty(key[0]) && child[key[0]].hasOwnProperty(key[1]) && child[key[0]][key[1]].hasOwnProperty(key[2])) + else if (len === 3 && key[0] in child && key[1] in child[key[0]] && key[2] in child[key[0]][key[1]]) { return true; } - else if (len === 4 && child.hasOwnProperty(key[0]) && child[key[0]].hasOwnProperty(key[1]) && child[key[0]][key[1]].hasOwnProperty(key[2]) && child[key[0]][key[1]][key[2]].hasOwnProperty(key[3])) + else if (len === 4 && key[0] in child && key[1] in child[key[0]] && key[2] in child[key[0]][key[1]] && key[3] in child[key[0]][key[1]][key[2]]) { return true; } @@ -696,7 +696,7 @@ Phaser.Group.prototype.setProperty = function (child, key, value, operation, for // We can't force a property in and the child doesn't have it, so abort. // Equally we can't add, subtract, multiply or divide a property value if it doesn't exist, so abort in those cases too. - if (!this.hasProperty(child, key, value) && (!force || operation > 0)) + if (!this.hasProperty(child, key) && (!force || operation > 0)) { return false; } diff --git a/src/input/Pointer.js b/src/input/Pointer.js index 9a02ebdb68..e9c220b1c7 100644 --- a/src/input/Pointer.js +++ b/src/input/Pointer.js @@ -385,7 +385,8 @@ Phaser.Pointer.prototype = { this.screenX = event.screenX; this.screenY = event.screenY; - if (this.isMouse && this.game.input.mouse.locked && !fromClick) { + if (this.isMouse && this.game.input.mouse.locked && !fromClick) + { this.rawMovementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0; this.rawMovementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0; @@ -393,7 +394,6 @@ Phaser.Pointer.prototype = { this.movementY += this.rawMovementY; } - this.x = (this.pageX - this.game.stage.offset.x) * this.game.input.scale.x; this.y = (this.pageY - this.game.stage.offset.y) * this.game.input.scale.y; @@ -662,8 +662,10 @@ Phaser.Pointer.prototype = { * @method Phaser.Pointer#resetMovement */ resetMovement: function() { + this.movementX = 0; this.movementY = 0; + } };