Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

kill all sprites in object layer?


owen
 Share

Recommended Posts

Hi there

 

Very quick question.... how do i kill all the sprites in the object layer?  (or at least, in a group)?

 

Do I need a forEach loop or is there some other way?

 

I cannot seem to find an example which kills every sprite.

 

The problem I am having is that when player respawns and I recreate the sprites on the map like this...

 

redApples = game.add.group();redApples.enableBody = true;    map.createFromObjects('Object Layer 1', RED_APPLE, 'redApple', 0, true, false, redApples);
....It is creating duplicate sprites of those which already exist.  I want to only create them where they don't already exist, or as it seems more simple, kill every existing sprite before calling createFromObjects.

 

Currently I am having to kill the sprites in each individual group, as below, and yes this works fine however this seems cumbersome (and risky in case I forget a group)  and I think I'm missing some way of doing it to the entire layer, all at once.

redApples.forEach(function (o) {        o.kill();    }, this, false);greenApples.forEach(function (o) {        o.kill();    }, this, false);

 

Thanks

Owen

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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