如果我同时按下两个键(向左箭头和向上箭头),我的球员位置向上或,但不在对角线方向。如何制作它以便捕获两个密钥代码?
以下是代码:
$(document).on("keydown", function(e) {
if(e.keyCode == player.upKey) {
player.y -= player.speed;
};
if(e.keyCode == player.downKey) {
player.y += player.speed;
};
if(e.keyCode == player.leftKey) {
player.x -= player.speed;
};
if(e.keyCode == player.rightKey) {
player.x += player.speed;
};
});