Domanda

I am using JQuery to handle all keypresses in my game, and I have the event handling down nicely, but I want to limit the player, in that if they press a key and hold it down it does NOT keep firing it.

Here is my current code:

    this.EventListener = function(){
    $(document).ready(function(){
        $(document).keydown(function(key){
            switch(parseInt(key.which, 10)){
                case AKey:
                case LeftArrow:
                    player.move(Left);
                    break;
                case DKey:
                case RightArrow:
                    player.move(Right);
                    break;
                case UpArrow:
                case Spacebar:
                    player.shoot();
                    break;
            }
        });
    });

Does anyone know how to implement something like this? I haven't been able to find anything like this...

È stato utile?

Soluzione

Change method from keydown to keyup ;) Try that.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top