Skip to content

Commit 664d5b3

Browse files
committed
Fixed issue where Image, Sprite, etc wouldn't call preUpdate or postUpdate of its children.
Fixed issue where renderOrderID wasn't being assigned correctly, causing the Input Handler to be unable to select the "top" item on a display list (would all default to zero) Fixed issue where Stage would assign renderOrderIDs in reverse, should be in sequence. Fixed issue where objects where checking World for the currentRenderOrderID by mistake instead of Stage. Basically, input handling works a lot better now for Groups and nested objects :)
1 parent 8dcfef8 commit 664d5b3

14 files changed

Lines changed: 226 additions & 76 deletions

File tree

build/custom/phaser-no-libs.js

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Phaser - http://www.phaser.io
99
*
10-
* v2.0.0 "Aes Sedai" - Built: Fri Feb 28 2014 18:53:23
10+
* v2.0.0 "Aes Sedai" - Built: Fri Feb 28 2014 19:43:09
1111
*
1212
* By Richard Davey http://www.photonstorm.com @photonstorm
1313
*
@@ -5315,6 +5315,11 @@ Phaser.Stage = function (game, width, height) {
53155315
*/
53165316
this.exists = true;
53175317

5318+
/**
5319+
* @property {number} currentRenderOrderID - Reset each frame, keeps a count of the total number of objects updated.
5320+
*/
5321+
this.currentRenderOrderID = 0;
5322+
53185323
/**
53195324
* @property {string} hiddenVar - The page visibility API event name.
53205325
* @private
@@ -5358,9 +5363,10 @@ Phaser.Stage.prototype.preUpdate = function () {
53585363

53595364
this.currentRenderOrderID = 0;
53605365

5361-
var i = this.children.length;
5366+
// This can't loop in reverse, we need the orderID to be in sequence
5367+
var len = this.children.length;
53625368

5363-
while (i--)
5369+
for (var i = 0; i < len; i++)
53645370
{
53655371
this.children[i].preUpdate();
53665372
}
@@ -7058,11 +7064,6 @@ Phaser.World = function (game) {
70587064
* @property {Phaser.Camera} camera - Camera instance.
70597065
*/
70607066
this.camera = null;
7061-
7062-
/**
7063-
* @property {number} currentRenderOrderID - Reset each frame, keeps a count of the total number of objects updated.
7064-
*/
7065-
this.currentRenderOrderID = 0;
70667067

70677068
}
70687069

@@ -11227,7 +11228,7 @@ Phaser.Pointer.prototype = {
1122711228
}
1122811229

1122911230
// Work out which object is on the top
11230-
this._highestRenderOrderID = -1;
11231+
this._highestRenderOrderID = Number.MAX_SAFE_INTEGER;
1123111232
this._highestRenderObject = null;
1123211233
this._highestInputPriorityID = -1;
1123311234

@@ -11239,11 +11240,11 @@ Phaser.Pointer.prototype = {
1123911240
do
1124011241
{
1124111242
// If the object is using pixelPerfect checks, or 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
11242-
if (currentNode.pixelPerfectClick || currentNode.pixelPerfectOver || currentNode.priorityID > this._highestInputPriorityID || (currentNode.priorityID === this._highestInputPriorityID && currentNode.sprite.renderOrderID > this._highestRenderOrderID))
11243+
if (currentNode.pixelPerfectClick || currentNode.pixelPerfectOver || currentNode.priorityID > this._highestInputPriorityID || (currentNode.priorityID === this._highestInputPriorityID && currentNode.sprite._cache[3] < this._highestRenderOrderID))
1124311244
{
1124411245
if ((!fromClick && currentNode.checkPointerOver(this)) || (fromClick && currentNode.checkPointerDown(this)))
1124511246
{
11246-
this._highestRenderOrderID = currentNode.sprite.renderOrderID;
11247+
this._highestRenderOrderID = currentNode.sprite._cache[3]; // renderOrderID
1124711248
this._highestInputPriorityID = currentNode.priorityID;
1124811249
this._highestRenderObject = currentNode;
1124911250
}
@@ -15965,14 +15966,15 @@ Phaser.Sprite.prototype.preUpdate = function() {
1596515966

1596615967
if (this.visible)
1596715968
{
15968-
this._cache[3] = this.game.world.currentRenderOrderID++;
15969+
this._cache[3] = this.game.stage.currentRenderOrderID++;
1596915970
}
1597015971

1597115972
this.animations.update();
1597215973

15973-
if (this.body)
15974+
// Update any Children
15975+
for (var i = 0, len = this.children.length; i < len; i++)
1597415976
{
15975-
// this.body.preUpdate();
15977+
this.children[i].preUpdate();
1597615978
}
1597715979

1597815980
return true;
@@ -15981,6 +15983,7 @@ Phaser.Sprite.prototype.preUpdate = function() {
1598115983

1598215984
/**
1598315985
* Override and use this function in your own custom objects to handle any update requirements you may have.
15986+
* Remember if this Sprite has any children you should call update on them too.
1598415987
*
1598515988
* @method Phaser.Sprite#update
1598615989
* @memberof Phaser.Sprite
@@ -16017,6 +16020,12 @@ Phaser.Sprite.prototype.postUpdate = function() {
1601716020
this.position.y = this.game.camera.view.y + this.cameraOffset.y;
1601816021
}
1601916022

16023+
// Update any Children
16024+
for (var i = 0, len = this.children.length; i < len; i++)
16025+
{
16026+
this.children[i].postUpdate();
16027+
}
16028+
1602016029
};
1602116030

1602216031
/**
@@ -16852,7 +16861,7 @@ Phaser.Image.prototype.preUpdate = function() {
1685216861

1685316862
if (!this.exists || !this.parent.exists)
1685416863
{
16855-
this.renderOrderID = -1;
16864+
this._cache[3] = -1;
1685616865
return false;
1685716866
}
1685816867

@@ -16866,7 +16875,13 @@ Phaser.Image.prototype.preUpdate = function() {
1686616875

1686716876
if (this.visible)
1686816877
{
16869-
this._cache[3] = this.game.world.currentRenderOrderID++;
16878+
this._cache[3] = this.game.stage.currentRenderOrderID++;
16879+
}
16880+
16881+
// Update any Children
16882+
for (var i = 0, len = this.children.length; i < len; i++)
16883+
{
16884+
this.children[i].preUpdate();
1687016885
}
1687116886

1687216887
return true;
@@ -16903,6 +16918,12 @@ Phaser.Image.prototype.postUpdate = function() {
1690316918
this.position.y = this.game.camera.view.y + this.cameraOffset.y;
1690416919
}
1690516920

16921+
// Update any Children
16922+
for (var i = 0, len = this.children.length; i < len; i++)
16923+
{
16924+
this.children[i].postUpdate();
16925+
}
16926+
1690616927
}
1690716928

1690816929
/**
@@ -17615,6 +17636,17 @@ Phaser.TileSprite.prototype.preUpdate = function() {
1761517636
this.tilePosition.y += this._scroll.y * this.game.time.physicsElapsed;
1761617637
}
1761717638

17639+
if (this.visible)
17640+
{
17641+
this._cache[3] = this.game.stage.currentRenderOrderID++;
17642+
}
17643+
17644+
// Update any Children
17645+
for (var i = 0, len = this.children.length; i < len; i++)
17646+
{
17647+
this.children[i].preUpdate();
17648+
}
17649+
1761817650
return true;
1761917651

1762017652
}
@@ -17644,6 +17676,12 @@ Phaser.TileSprite.prototype.postUpdate = function() {
1764417676
this.position.y = this.game.camera.view.y + this.cameraOffset.y;
1764517677
}
1764617678

17679+
// Update any Children
17680+
for (var i = 0, len = this.children.length; i < len; i++)
17681+
{
17682+
this.children[i].postUpdate();
17683+
}
17684+
1764717685
}
1764817686

1764917687
/**
@@ -18107,7 +18145,13 @@ Phaser.Text.prototype.preUpdate = function () {
1810718145

1810818146
if (this.visible)
1810918147
{
18110-
this._cache[3] = this.game.world.currentRenderOrderID++;
18148+
this._cache[3] = this.game.stage.currentRenderOrderID++;
18149+
}
18150+
18151+
// Update any Children
18152+
for (var i = 0, len = this.children.length; i < len; i++)
18153+
{
18154+
this.children[i].preUpdate();
1811118155
}
1811218156

1811318157
return true;
@@ -18136,6 +18180,12 @@ Phaser.Text.prototype.postUpdate = function () {
1813618180
this.position.y = this.game.camera.view.y + this.cameraOffset.y;
1813718181
}
1813818182

18183+
// Update any Children
18184+
for (var i = 0, len = this.children.length; i < len; i++)
18185+
{
18186+
this.children[i].postUpdate();
18187+
}
18188+
1813918189
}
1814018190

1814118191
/**
@@ -18967,7 +19017,7 @@ Phaser.BitmapText.prototype.preUpdate = function () {
1896719017

1896819018
if (this.visible)
1896919019
{
18970-
this._cache[3] = this.game.world.currentRenderOrderID++;
19020+
this._cache[3] = this.game.stage.currentRenderOrderID++;
1897119021
}
1897219022

1897319023
return true;
@@ -19997,7 +20047,7 @@ Phaser.Graphics.prototype.preUpdate = function () {
1999720047

1999820048
if (this.visible)
1999920049
{
20000-
this._cache[3] = this.game.world.currentRenderOrderID++;
20050+
this._cache[3] = this.game.stage.currentRenderOrderID++;
2000120051
}
2000220052

2000320053
return true;

build/custom/phaser-no-libs.min.js

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)