Original Post
I haven't been programming lately and Im kind of rusty. I need to program a pause function for my game. I am using javascript and html, just trying to move around a stick figure. Here is my game loop code. Whats happening is that its not pausing, you push the button it pauses for a second and then starts again. I know it's becuase the loop it going and its doing just what I've coded. I just can't think of anything to get around it.
function gameLoop(){
clearTimeout(gameTimer);
if(pauseKey.pressed){
if(pause){
pause = false;
}else{
pause = true;
}
}
if(pause){
gameTimer = setTimeout("gameLoop()",10);
}else if(!gameOver){
checkKeys();
gravity();
checkExit();
checkEnemies();
moveEnemies();
gameTimer = setTimeout("gameLoop()",10);
}
}