0

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.

JasonMArcher
15.2k22 gold badges59 silver badges53 bronze badges
asked Sep 2, 2014 at 19:00
1
  • Assume that any keys that aren't "down" are up - you could start building out a map on each keydown, ex: var keysDown = {}; //onkeydown keysDown[e.which] = true then onkeyup, set it to false, and you can then check that map for keycodes of currently pressed buttons Commented Sep 2, 2014 at 19:05

1 Answer 1

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

answered Sep 2, 2014 at 19:05
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.