owen Posted August 24, 2014 Share Posted August 24, 2014 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); ThanksOwen Link to comment Share on other sites More sharing options...
Recommended Posts