So, I have this function, which for some reason at some point starts throwing an "enemies[i] is undefined" error. The function is constantly called in the game loop.
function moveEnemies() {
for(i = 0; i < enemies.length; i++) {
enemies[i].y += FE_SPEED;
enemies[i].c.attr("y", friends[i].y);
if(enemies[i].y > 640)
delete enemies[i];
}
for(i = 0; i < enemies.length; i++) {
if(!enemies[i])
enemies.splice(i, 1);
}
}
What am I doing wrong?