deerob4 Posted April 4, 2014 Share Posted April 4, 2014 Hello, I'm having a bit of a problem destroying sprites in a group. The group is called "enemies", and they are generated using this loop: for (var i = 0; i < 10; i++) {var enemy = enemies.create(game.world.randomX, game.world.randomY, 'enemy');enemy.checkWorldBounds = true;enemy.events.onOutOfBounds.add(removeEnemy, this);}The removeEnemy function contains a simple enemy.kill(), but this does not remove them from memory, so isn't very efficient. I've tried using enemy.destroy(), but this results in:Uncaught TypeError: Cannot read property 'camera' of null How can I make the destroy() function work? Thanks! Link to comment Share on other sites More sharing options...
Martiny Posted April 4, 2014 Share Posted April 4, 2014 Are you passing the enemy as an argument in removeEnemy()? I mean, I guess it should work if the function is like this: removeEnemy(enemy) {enemy.kill();} It's the only thing I can think of for now. // edit: I misunderstood your question, sorry. Can't help then ): In the error there should be the line of code that the error occurred, can you show it? Maybe it will help us understand. Link to comment Share on other sites More sharing options...
Heppell08 Posted April 4, 2014 Share Posted April 4, 2014 var i;enemy.getAt(i).kill();Try that in the removeEnemy function. codevinsky 1 Link to comment Share on other sites More sharing options...
Recommended Posts