I’m making a side scroller game and want to move the player across the screen using the arrow keys on the keyboard. I am able to move him fine, but he always seems to move over once, pause and then continue moving until i let go of the key. I want to get rid of that little pause that keeps occuring.
I tried to minimalize the code as much as I could and I was sure that having a loop to keep the player moving until the key was released would make it smooth, but the lag is still there.
Any ideas on why this happens or how I can move the player smoothly would be much appreciated, thanks!
var keyNowUp:Boolean = true;
stage.addEventListener(KeyboardEvent.KEY_DOWN, movePlayer);
stage.addEventListener(KeyboardEvent.KEY_UP, stopPlayer);
function movePlayer(event:KeyboardEvent)
{
keyNowUp = false;
do {
player.x += 10;
} while(keyNowUp = false)
}
function stopPlayer(event:KeyboardEvent)
{
keyNowUp = true;
}