Mike Posted November 13, 2013 Share Posted November 13, 2013 I got this setup:update: function() { this.balls.forEach(this.ballUpdate, this);}ballUpdate: function(ball) {if (ball.body.y > this.game.world.height + ball.height) {ball.destroy();}}Which results in: Uncaught TypeError: Cannot read property 'alive' of null Game.js:566 BasicGame.Game.ballUpdateGame.js:566 Phaser.Group.forEachphaser.js:12324 BasicGame.Game.updateGame.js:173 Phaser.StateManager.updatephaser.js:10138 Phaser.Game.updatephaser.js:13701 Phaser.RequestAnimationFrame.updateRAFphaser.js:22114 _onLoopphaser.js:22099 I tried: update: function() { if(this.balls.countLiving() > 0) { this.balls.forEach(this.ballUpdate, this); }} Link to comment Share on other sites More sharing options...
Vidsneezes Posted November 13, 2013 Share Posted November 13, 2013 I'm not sure if it was a typo, but your ballUpdate function is missing the ball as a parameter. Link to comment Share on other sites More sharing options...
Mike Posted November 14, 2013 Author Share Posted November 14, 2013 Yes, It was Typo, I'll upload the full game example soon if I don't find a fix... if I find then soon the whole game will be publicly available Link to comment Share on other sites More sharing options...
Terumi Posted November 15, 2013 Share Posted November 15, 2013 Do you use masks?If you have a mask applied to a group, that group acuires some members that are not sprites... Link to comment Share on other sites More sharing options...
Mike Posted November 15, 2013 Author Share Posted November 15, 2013 No masks, nothing a simple group with sprites.... I'll make an "buggy example" later this night. Link to comment Share on other sites More sharing options...
hackenstein Posted November 16, 2013 Share Posted November 16, 2013 Heh, I have run into a similar problem. I have a group of display objects (text, sprites and buttons) that I want to destroy before removing everything in the group:this.group.forEach(function(obj) { if (obj.kill) obj.kill(); else if (obj.destroy) obj.destroy();});this.group.removeAll();This results in an "Type Error: obj is null". EDIT: I'm pretty sure this happens because Sprite.destroy now removes the sprite from its group. So you shouldn't destroy objects in a group with forEach Link to comment Share on other sites More sharing options...
Recommended Posts