Trying to destroy baddies in remix of show examples in game lab of group → get(i) example.
See screen if I take out line 30 temp.destroy(); I can set the animation fine. However, if I try and destroy the sprite being accessed via the index, I get an error in the setAnimation line above, which is weird.
27 for (var i = 0; i < 50; i++) {
28 var temp = mgroup.get(i);
29 temp.setAnimation(“sax”);
30 temp.destroy();}
// Stay cool! Keep all the bad vibes from getting you down.
// Uses createGroup to make a bunch of bouncing baddies,
// createEdgeSprites to make sure the baddies don’t just fly off.
var cool = createSprite(200, 200);
cool.setAnimation(“kidportrait_05_1”);
cool.scale = 0.15;
createEdgeSprites();
var mgroup = createGroup();
for (var i = 0; i < 100; i++) {
var sprite = createSprite(randomNumber(0, 400), randomNumber(0, 100), 10, 10);
sprite.velocityY=randomNumber(5, 10);
sprite.velocityX=randomNumber(-5, 5);
sprite.bounciness = 1;
mgroup.add(sprite);
}
mgroup.setAnimationEach(“gameplaywacky_01_1”);
mgroup.setScaleEach(0.25);
function draw() {
background(“white”);
drawSprites();
cool.x = World.mouseX;
cool.y = World.mouseY;
for (var i = 0; i < 50; i++) {
var temp = mgroup.get(i);
temp.setAnimation(“sax”);
temp.destroy();
}
mgroup.bounceOff(cool);
mgroup.bounceOff(bottomEdge);
mgroup.bounceOff(topEdge);
mgroup.bounceOff(leftEdge);
mgroup.bounceOff(rightEdge);
}