slight disclaimer, i'm relatively new to JavaScript and i'm not the best, although I guess that begs the question how do you define "best". Anyway I digress. My question is when I am moving an object around the canvas why is it slow (stuttery) and only one key press can be registered at one time. Is there a way to make it more smooth and so that you can register multiple keys at a time?
// player movement
window.onkeydown = function playermovement () {
var keypress = event.which || event.keyCode;
//up
if (keypress == 87 && player.y >0) {
player.y = player.y -20
}
//down
if (keypress == 83 && player.y < 400) {
player.y = player.y + 20
}
if (keypress == 38) {
player2.y = player2.y -20
}
if (keypress == 40) {
player2.y = player2.y +20
}
}
Thank you
James