JavaScript中的暂停菜单?



我正在尝试为游戏制作暂停菜单,我和我的朋友正在制作,我想知道js是否有一种简单的方法来制作暂停游戏的按键功能?有吗?谢谢你!

尝试添加一个带有你想要游戏暂停键的事件监听器:

// adds an event listener to the document that listens for key presses
document.addEventListener("keydown", function(e) {
// if desired key pressed, pause 
// Replace Escape with the key you want to execute the pause function
if (e.key === "Escape") {
pause();
// else do nothing
} else {}
});

要查找要执行该函数的键的键代码,我建议使用keycode.info。

最新更新