group.clear()

Category:Groups

Delete the group but not the sprites in the group.

Examples

// 100 blinks then remove the group.
var group = createGroup();
for (var i = 0; i < 20; i++) {
  group.add(createSprite(randomNumber(0, 400), randomNumber(0, 400),randomNumber(10, 20),randomNumber(10, 20)));
}
var counter=1;
function draw() {
  background("white");
  drawSprites();
  counter=counter+1;
  if (counter%2==1) group.setColorEach("red");
  else group.setColorEach("green"); 
  if (counter>100) group.clear();
}

Syntax

group.clear()

Returns

No return value. Changes output in the display after drawSprites() is called.

Tips

  • Groups of sprites all have the same functions and you use the dot notation (combining the name of the group, followed by a dot, with the function name) to call the function for that group of sprites.
  • Any changes to the properties of a sprite will not be seen until after drawSprites() is called.

Found a bug in the documentation? Let us know at documentation@code.org