When this variable becomes a certain amount i want the loop to stop, but i keep getting the error, \"Uncaught SyntaxError: Illegal break statement\".
function lo
You need to make sure requestAnimFrame stops being called once game == 1. A break statement only exits a traditional loop (e.g. while()
).
function loop() {
if (isPlaying) {
jet1.draw();
drawAllEnemies();
if (game != 1) {
requestAnimFrame(loop);
}
}
}
Or alternatively you could simply skip the second if
condition and change the first condition to if (isPlaying && game !== 1)
. You would have to make a variable called game and give it a value of 0. Add 1 to it every game.