So I draw an object on the screen at objectx, objecty and increment objectx when right arrow is pressed, moving the object to the right. The problem I'm running into is that if I hold the right arrow key down it increments once, pauses, and then increments repeatedly. My question is why does it do this, and how can I make the object move fluidly without that initial pause?
$(window).keydown(function(e) {
if(e.keyCode == 39) {
objectx++;
}
}
Make an interval that increases the objects, on key down, and stop the interval on keyup. (Save the interval ID somewhere, also make sure to not make the interval twice when it's already there)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With