Pausing my game issue in ActionScript 3

50 views Asked by At

In my game I'm trying to add a Pause function, pressing P key. It works but the problem is that if the mouse stands still and I press P key, nothing happens but while I move the mouse it fastly works. to resume there is no problem. How can I fix that, to let it work without moving the mouse? Here is the code

stage.addEventListener(KeyboardEvent.KEY_DOWN, pauseGame);
function pauseGame(e:KeyboardEvent):void{
     if(!gamePaused && (e.keyCode == 80)){
     rect_Darken.x = STAGE_CENTER.x;
     rect_Darken.y = STAGE_CENTER.y;
     txt_Pause.x = STAGE_CENTER.x;
     txt_Pause.y = STAGE_CENTER.y;
     gamePaused = true;
     stage.frameRate = 0;
     }else if(e.keyCode == 80){
     stage.frameRate = 24;
     rect_Darken.x = 270;
     rect_Darken.y = 670;
     txt_Pause.x = 270;
     txt_Pause.y = 670;
     gamePaused = false;
     }
}
0

There are 0 answers