Rinkusu – 23-59 Jan 29

Hi, how do I make the keyboard detection "game-friendly" please ? It's for a pong game, for now the keyboard detection works just as usual for text input
L
LaRynk810d ago
I mean when I press a key there's a short moment when it doesn't move
UU
Unknown User810d ago
L
LaRynk810d ago
document.addEventListener('keydown', (e) => manageInputs(e.key))
document.addEventListener('keydown', (e) => manageInputs(e.key))
UU
Unknown User810d ago
L
LaRynk810d ago
function manageInputs(key) {
switch(key) {
case 'a':
leftRectY - 10 >= 5 && (leftRectY -= 10)
break
case 'q':
leftRectY + 10 <= 485 && (leftRectY += 10)
break
case 'ArrowUp':
rightRectY - 10 >= 5 && (rightRectY -= 10)
break
case 'ArrowDown':
rightRectY + 10 <= 485 && (rightRectY += 10)
}
}
function manageInputs(key) {
switch(key) {
case 'a':
leftRectY - 10 >= 5 && (leftRectY -= 10)
break
case 'q':
leftRectY + 10 <= 485 && (leftRectY += 10)
break
case 'ArrowUp':
rightRectY - 10 >= 5 && (rightRectY -= 10)
break
case 'ArrowDown':
rightRectY + 10 <= 485 && (rightRectY += 10)
}
}
UU
Unknown User810d ago
UU
Unknown User810d ago
L
LaRynk810d ago
I don't get what I should do with that, doesn't look like 'keyup' is the thing
UU
Unknown User810d ago
L
LaRynk809d ago
thx a lot !
UU
Unknown User809d ago