I tried to clone Flappy Bird and when the user collides i want to stop the animation frame and display page with last score and button . i tried this
function render(){
jumpCheck();
drawMovePipes();
writeScore();
interval=requestAnimationFrame(render)
}
and i begin the window by
$('startScreen').onclick=()=>{
screen.canvas.style.display="block";
$('startScreen').style.display="none";
interval=window.requestAnimationFrame(render);
}
When collison is happended this function is called
function collided(){
cancelAnimationFrame(interval);
screen.canvas.style.display="none";
$('h3').innerText+=`Last Score ${score}`
$('startScreen').style.display="block";
}
here the problem is the loop runs constantly and keeps adding the “last Score” text repeatedly . how to completely break from the loop like game pause or exit .