I'm building a GIF animation based movement system for my game.
The question is, once the keycode (lets say 37) is down, how do I detect if/when that certain key is up?
I want to move the charater and play the GIF while the key is down, but I need to stop the animation and stop the character from moving when the key is up.
1 Answer 1
I assume you're using the onkeydown event described here to catch an action:
http://www.w3schools.com/jsref/event_onkeydown.asp
Why not use the opposite function to detect when an action should stop? It's called onkeyup, and it's described here:
http://www.w3schools.com/jsref/event_onkeyup.asp
var keysDown = {}; //onkeydown keysDown[e.which] = truethen onkeyup, set it to false, and you can then check that map for keycodes of currently pressed buttons