在我的游戏中,我尝试添加暂停功能,按下 P 键。它可以工作,但问题是如果鼠标静止并且我按下 P 键,什么也不会发生,但是当我移动鼠标时它会快速工作。恢复没有问题。我该如何解决这个问题,让它在不移动鼠标的情况下工作?这是代码
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;
}
}