1

I am trying to make a browser game (using createjs, if this makes a difference) and the problem I'm trying to figure out is how do I get the event keydown in a loop, and no sudden.

For example,

createjs.Ticker.setFPS(60);
createjs.Ticker.addEventListener("tick", function() {

    // here
    if (isUpArrowKeyPressed) {
        movePlayerUp(); // This is an example, ignore this
    }

});

So this way, if the key is pressed for exactly 1 second it would do what is inside it 60 times. (60fps)

Any way to do this?

Joe Tannoury
  • 145
  • 10
  • Take a look at http://stackoverflow.com/questions/23717091/easeljs-keyboard-ticker-problems. This should move you in the right direction (no pun intended) – Erik Ahlswede Mar 28 '16 at 19:38
  • https://stackoverflow.com/questions/1828613/check-if-a-key-is-down –  Mar 28 '16 at 19:39
  • thanks guys, you rock. what should I do with the question, delete it? – Joe Tannoury Mar 28 '16 at 19:43
  • If you work out a nice answer, you can answer it yourself, it may help other people in future :) – DBS Mar 28 '16 at 19:47

1 Answers1

2

You'll want to pass in the event parameter to your function. From there you'll be able to see which key was pressed

createjs.Ticker.addEventListener("keydown", function(e) {
   var keyCode = e.keyCode

   // Compare the keycode
   if (keyCode === 57) {
       movePlayerUp(); // This is an example, ignore this
   }

});
GSaunders
  • 548
  • 1
  • 5
  • 15