There's a strange glitch that pops up when trying to delete every sprite in a group. I have a group called squaresNoCollide
, which contains 68 sprites. I want to delete all of the sprites in this group at once, which the function below is supposed to do:
function clearAll() {
for (var i = 0; i < squaresNoCollide.length; i++) {
var sprite = squaresNoCollide.get(i);
sprite.destroy();
}
}
But instead it deletes only 34 of the sprites. If I run the loop twice it just deletes half of the sprites again, so the first time it deletes 34, then 16, and so on.
Any ideas on how to fix this? Or, if there's a way to delete every sprite in a group without using a loop at all, that would be helpful too.