I'm having trouble with quiting/killing/exitting my requestAnimationFrame. My gameloop works, i can pause my game (gameloop stays active). But when I want to return to my menu, I want to kill the requestAnimationFrame, so it stops drawing and updating. I've searched on the internet and stackoverflow, found similar questions tried te response, but no luck :(
var fps = 60;
var now;
var then = Date.now();
var interval = 1000/fps;
var delta;
//============================================================================
function gameloop(){
window.requestAnimationFrame(gameloop);
if (game.isUnpaused()){
//game is not paused, update all
now = Date.now();
delta = now - then;
if (delta > interval) {
then = now - (delta % interval);
//DO ALL WHAT'S NEEDED: draw avatar,move obstacles,move avatar....
}}
//what to do when game is paused:
else{//draw stuff when game is paused}
}
Can Anybody help me?
Thanks in advance