2

Some might think its a duplicate of:

JavaScript multiple keys pressed at once

Detect multiple keys on single keypress event in jQuery

Can jQuery .keypress() detect more than one key at the same time?

or my old post : How can I catch 2+ key presses at once?

But the answer they offer does not solve the issue i am facing.

Lets say you click on left key and hold then add up key for a second and then release up key. in the above questions the "keydown" event stop firing until you release it and click it again. E.G : http://jsfiddle.net/gFcuU/586/ open console log and try the above steps you'll see what i am talking about.

You can also try my old code and see the same issue at : http://jsfiddle.net/dB553/1/

My solution to it was setting an interval that will act like "refresh" for the whole "game" you can see it at: http://jsfiddle.net/2Nn9T/3/

you'll notice how smooth the movement compared to the other way.

**My question is: ** is there a better way to achieve the same thing without intervals ?

The interval I set looks like:

this.fnStartTimers = function(){
    this.oRgfInterval = setInterval(function(){ that.fnRefreshGame(); },this.iRefreshGameFrequency);
    this.oGcInterval = setInterval( function(){ that.fnGlobalCooldown(); } ,this.iGlobalCoolDown);
}
Community
  • 1
  • 1
Neta Meta
  • 4,001
  • 9
  • 42
  • 67
  • Looking in the code, I think you are on the right path with intervals. You could use helper function to test for key combinations, but action game is likely to be interval based. – nrodic May 02 '14 at 23:02

0 Answers0