Jump to content

Issue destroying sprites


Recommended Posts



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?



Link to comment
Share on other sites

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) {




It's the only thing I can think of for now.






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


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...