Remove a sprite from the group.
In some animations or games you might need to remove a sprite from a group so it will act on its own instead of with the group. remove() does not delete sprite. Sprite.remove() will also remove the sprite from all the groups it belongs to.
// Press 1, 2 or 3 to remove a sprite from the group and have it stop following the mouse. var box1 = createSprite(75, 200, 50, 50); var box2 = createSprite(200, 200, 50, 50); var box3 = createSprite(325, 200, 50, 50); var group = createGroup(); group.add(box1); group.add(box2); group.add(box3); function draw() { background("white"); drawSprites(); if (keyWentDown("1")) { group.remove(box1); } if (keyWentDown("2")) { group.remove(box2); } if (keyWentDown("3")) { group.remove(box3); } var direction=(180*Math.atan2(World.mouseY-200, World.mouseX-200))/Math.PI; group.setSpeedAndDirectionEach(1, direction); }
group.remove(sprite)
Name | Type | Required? | Description |
---|---|---|---|
sprite | Sprite | The sprite to remove from the group. |
No return value.
drawSprites()
is called.Found a bug in the documentation? Let us know at documentation@code.org