Working on just having smooth movement of a square in javascript. At the moment it is very choppy and not at all smooth. This is what I am using at the moment:
window.addEventListener('keydown', function(event) {
if(!dead && playing){
switch (event.keyCode) {
case 37:
moveLeft = true;
break;
case 38:
moveUp = true;
break;
case 39:
moveRight = true;
break;
case 40:
moveDown = true;
break;
}
};
}, false);
function GameLoop(){
if(moveLeft){
x -= 6;
moveLeft = false;
}else if(moveUp){
y -= 6;
moveUp = false;
}else if(moveRight){
x += 6;
moveRight = false;
}else if(moveDown){
y += 6;
moveDown = false;
}
if(playArcade){
setTimeout(GameLoop, 33);
}
I read this blog post about on the topic of smooth movement in javascript: http://nokarma.org/2011/02/27/javascript-game-development-keyboard-input/index.html
However, I did not understand a lot of it, although I think it contains the answer to my problem. If some could explain what the blog post says/means to a noob like myself that would be great - or find another solution to my problem.
p.s. I may have missed some of the detail in the code posted above, if some of the variables and other items are missing, its just because I did not post them in this code, they are in the real thing though.