• Question
  • Is it possible to destroy a single sprite from a group in gamelab?

Specifically, is it possible to remove a specific sprite that has both created and added to a group by a for loop
Maybe while it's touching an ungrouped sprite

an example of said type of thing just in case
`var coolgroup = createGroup();

for (var i = 0; i < 3; i++) {
var thing = createSprite(200,200);
coolgroup.add(thing);
}`

  • Varrience replied to this.
  • Mellow, Captain_Jack_Sparrow, Varrience, Ravage, gZany, Binary_Coder, person, Letti42, ackvonhuelio, INTERNECION, Flowey_the_Flower, 3321, Blockyheadman, and 8 others viewed this.
  • Mellow well if were referring to an array here splice would be the proper protocol and you can call destroy before removing it from the array to that is if destroy doesn't do it for you already

    for(var i  = 0; i < sprites.length; i++) {
     var current = sprite[i];
     if(current.isTouching(player)) {
      current.destroy();
      sprites.splice(i, 1);
     }
    } 

    i think something like this should do the trick idk i don't use groups anymore

    Mellow well if were referring to an array here splice would be the proper protocol and you can call destroy before removing it from the array to that is if destroy doesn't do it for you already

    for(var i  = 0; i < sprites.length; i++) {
     var current = sprite[i];
     if(current.isTouching(player)) {
      current.destroy();
      sprites.splice(i, 1);
     }
    } 

    i think something like this should do the trick idk i don't use groups anymore

    Chat