Group.setProperty will now check if the property exists before setting it, this applies to Group.setAll and anything else using setProperty internally.

This commit is contained in:
photonstorm 2014-04-17 12:11:37 +01:00
parent b77c034f61
commit 7c9f079ce5
3 changed files with 6 additions and 7 deletions

View file

@ -65,6 +65,7 @@ Version 2.0.4 - "Mos Shirare" - in development
* AnimationManager.destroy now iterates through child animations calling destroy on all of them, avoiding a memory leak (thanks stauzs)
* AnimationManager.play will now call Animation.stop on the current animation before switching to the new one (thanks @nihakue, #713)
* ArcadePhysics.Body.phase is checked in postUpdate to prevent it from being called multiple times in a single frame.
* Group.setProperty will now check if the property exists before setting it, this applies to Group.setAll and anything else using setProperty internally.
### New Features

Binary file not shown.

After

Width:  |  Height:  |  Size: 634 KiB

View file

@ -635,9 +635,7 @@ Phaser.Group.prototype.setProperty = function (child, key, value, operation) {
operation = operation || 0;
// As ugly as this approach looks, and although it's limited to a depth of only 4, it's extremely fast.
// Much faster than a for loop or object iteration. There are no checks, so if the key isn't valid then it'll fail
// but as you are likely to call this from inner loops that have to perform well, I'll take that trade off.
// As ugly as this approach looks, and although it's limited to a depth of only 4, it's much faster than a for loop or object iteration.
// 0 = Equals
// 1 = Add
@ -647,7 +645,7 @@ Phaser.Group.prototype.setProperty = function (child, key, value, operation) {
var len = key.length;
if (len == 1)
if (len === 1 && child.hasOwnProperty(key[0]))
{
if (operation === 0) { child[key[0]] = value; }
else if (operation == 1) { child[key[0]] += value; }
@ -655,7 +653,7 @@ Phaser.Group.prototype.setProperty = function (child, key, value, operation) {
else if (operation == 3) { child[key[0]] *= value; }
else if (operation == 4) { child[key[0]] /= value; }
}
else if (len == 2)
else if (len === 2 && child.hasOwnProperty(key[0]) && child[key[0]].hasOwnProperty(key[1]))
{
if (operation === 0) { child[key[0]][key[1]] = value; }
else if (operation == 1) { child[key[0]][key[1]] += value; }
@ -663,7 +661,7 @@ Phaser.Group.prototype.setProperty = function (child, key, value, operation) {
else if (operation == 3) { child[key[0]][key[1]] *= value; }
else if (operation == 4) { child[key[0]][key[1]] /= value; }
}
else if (len == 3)
else if (len === 3 && child.hasOwnProperty(key[0]) && child[key[0]].hasOwnProperty(key[1]) && child[key[0]][key[1]].hasOwnProperty(key[2]))
{
if (operation === 0) { child[key[0]][key[1]][key[2]] = value; }
else if (operation == 1) { child[key[0]][key[1]][key[2]] += value; }
@ -671,7 +669,7 @@ Phaser.Group.prototype.setProperty = function (child, key, value, operation) {
else if (operation == 3) { child[key[0]][key[1]][key[2]] *= value; }
else if (operation == 4) { child[key[0]][key[1]][key[2]] /= value; }
}
else if (len == 4)
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]))
{
if (operation === 0) { child[key[0]][key[1]][key[2]][key[3]] = value; }
else if (operation == 1) { child[key[0]][key[1]][key[2]][key[3]] += value; }