As you're already using jQuery, you could take advantage of jQuery's animation support. In controls.js
, replace:
$('#objUserCore').css('left',$('#objUserCore').position().left + (gameSpeed * playerSpeed));
with:
$('#objUserCore').animate({ 'left': '+=' + (gameSpeed * playerSpeed) });
jQuery will spin off the appropriate timers to animate your sprite smoothly and efficiently. The '+=' syntax tells jQuery to animate the value starting from its present value, and adding the specified difference. You can find the details in the jQuery documentation.
To get the animation effect going in all four directions, replace all four if statements in controls.js
:
if (event.keyCode == '39')
$('#objUserCore').animate({ 'left': '+=' + (gameSpeed * playerSpeed) });
if (event.keyCode == '37')
$('#objUserCore').animate({ 'left': '-=' + (gameSpeed * playerSpeed) });
if (event.keyCode == '38')
$('#objUserCore').animate({ 'top': '-=' + (gameSpeed * playerSpeed) });
if (event.keyCode == '40')
$('#objUserCore').animate({ 'top': '+=' + (gameSpeed * playerSpeed) });