Easiest way to do a smooth rapid fire with gameQuery?
  • I'm enjoying the keypressing functionality, but now realize that it would be a smoother and less damaging experience for the user if we had to the ability to rapid fire, i.e. (launch missiles continuously from the main player by keeping your finger down on the fire button, one missile coming out every xth of a millisecond). I tried nesting a kepress call inside of registerCallback() like this...

    $.playground().registerCallback(function(){
    /*when key is pressed down*/
    $(document).keydown(function(e){
    if(!game.playerHit){
    switch(e.keyCode){
    case 75: /*adjust and fire player weapon (k)*/
    player.fireweapon();
    break;
    }
    }
    });
    },1000);

    but its not firing the missiles smoothly in good timing...any advise would be great!
  • selimselim
    Accepted Answer
    Instead of using events you should use the key tracker. Just enable it by passing keyTracker: true in the playground options. Then you can simply acces the array $.gQ.keyTracker where the value at the indexes represented by keyCodes is true if the corresponding key is presses.

    Then you create a callback that you register with a frequency equal to your firering rate where you check the status of the 'fire' key.
  • Thanks again Selim! I also read up on your post here to make this solution work perfect for me... http://forum.gamequeryjs.com/discussion/27/keytracker-documentation-mouse-click-support/p1

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!