Skip to content

Commit 49a6ba2

Browse files
committed
Updated Group to fix some issues with not checking children
1 parent 1bf838a commit 49a6ba2

2 files changed

Lines changed: 30 additions & 11 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ Although Phaser 1.0 is a brand new release it is born from years of experience b
113113

114114
![Phaser Particles](http://www.photonstorm.com/wp-content/uploads/2013/04/phaser_particles.png)
115115

116+
Change Log
117+
----------
118+
119+
* Added checks into every Group function to ensure that the Group has children before running them.
120+
* Added optional flag to Group.create which allows you to set the default exists state of the Sprites.
121+
116122
Known Issues
117123
------------
118124

src/core/Group.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,14 @@ Phaser.Group.prototype = {
9191

9292
},
9393

94-
create: function (x, y, key, frame) {
94+
create: function (x, y, key, frame, exists) {
95+
96+
if (typeof exists == 'undefined') { exists = true; }
9597

9698
var child = new Phaser.Sprite(this.game, x, y, key, frame);
9799

98100
child.group = this;
101+
child.exists = exists;
99102

100103
if (child.events)
101104
{
@@ -379,7 +382,7 @@ Phaser.Group.prototype = {
379382
checkVisible = checkVisible || false;
380383
operation = operation || 0;
381384

382-
if (this._container.first._iNext)
385+
if (this._container.children.length > 0 && this._container.first._iNext)
383386
{
384387
var currentNode = this._container.first._iNext;
385388

@@ -430,7 +433,7 @@ Phaser.Group.prototype = {
430433

431434
var args = Array.prototype.splice.call(arguments, 2);
432435

433-
if (this._container.first._iNext)
436+
if (this._container.children.length > 0 && this._container.first._iNext)
434437
{
435438
var currentNode = this._container.first._iNext;
436439

@@ -453,7 +456,7 @@ Phaser.Group.prototype = {
453456

454457
if (typeof checkExists == 'undefined') { checkExists = false; }
455458

456-
if (this._container.first._iNext)
459+
if (this._container.children.length > 0 && this._container.first._iNext)
457460
{
458461
var currentNode = this._container.first._iNext;
459462

@@ -474,7 +477,7 @@ Phaser.Group.prototype = {
474477

475478
forEachAlive: function (callback, callbackContext) {
476479

477-
if (this._container.first._iNext)
480+
if (this._container.children.length > 0 && this._container.first._iNext)
478481
{
479482
var currentNode = this._container.first._iNext;
480483

@@ -495,7 +498,7 @@ Phaser.Group.prototype = {
495498

496499
forEachDead: function (callback, callbackContext) {
497500

498-
if (this._container.first._iNext)
501+
if (this._container.children.length > 0 && this._container.first._iNext)
499502
{
500503
var currentNode = this._container.first._iNext;
501504

@@ -525,7 +528,7 @@ Phaser.Group.prototype = {
525528
state = true;
526529
}
527530

528-
if (this._container.first._iNext)
531+
if (this._container.children.length > 0 && this._container.first._iNext)
529532
{
530533
var currentNode = this._container.first._iNext;
531534

@@ -553,7 +556,7 @@ Phaser.Group.prototype = {
553556
*/
554557
getFirstAlive: function () {
555558

556-
if (this._container.first._iNext)
559+
if (this._container.children.length > 0 && this._container.first._iNext)
557560
{
558561
var currentNode = this._container.first._iNext;
559562

@@ -581,7 +584,7 @@ Phaser.Group.prototype = {
581584
*/
582585
getFirstDead: function () {
583586

584-
if (this._container.first._iNext)
587+
if (this._container.children.length > 0 && this._container.first._iNext)
585588
{
586589
var currentNode = this._container.first._iNext;
587590

@@ -610,7 +613,7 @@ Phaser.Group.prototype = {
610613

611614
var total = -1;
612615

613-
if (this._container.first._iNext)
616+
if (this._container.children.length > 0 && this._container.first._iNext)
614617
{
615618
var currentNode = this._container.first._iNext;
616619

@@ -639,7 +642,7 @@ Phaser.Group.prototype = {
639642

640643
var total = -1;
641644

642-
if (this._container.first._iNext)
645+
if (this._container.children.length > 0 && this._container.first._iNext)
643646
{
644647
var currentNode = this._container.first._iNext;
645648

@@ -669,6 +672,11 @@ Phaser.Group.prototype = {
669672
*/
670673
getRandom: function (startIndex, length) {
671674

675+
if (this._container.children.length == 0)
676+
{
677+
return null;
678+
}
679+
672680
startIndex = startIndex || 0;
673681
length = length || this._container.children.length;
674682

@@ -705,6 +713,11 @@ Phaser.Group.prototype = {
705713

706714
removeBetween: function (startIndex, endIndex) {
707715

716+
if (this._container.children.length == 0)
717+
{
718+
return;
719+
}
720+
708721
if (startIndex > endIndex || startIndex < 0 || endIndex > this._container.children.length)
709722
{
710723
return false;

0 commit comments

Comments
 (0)