samedi 21 janvier 2017

(Actionscript 3.0) How to fix this arrow control glitch?

Currently, I am trying to make a game, but I ran into a couple of problems. One of them is that I have to click the screen for the arrow controls to work. Is there anyway to fix that?

Secondly, the arrow keys work as intended, but the WASD keys do not. Why is that?

private function key_down(event:KeyboardEvent): void{
        if(event.keyCode == Keyboard.LEFT || event.keyCode == 65){
            leftPressed=true;  
        }
        if(event.keyCode == Keyboard.RIGHT || event.keyCode == 68){
            rightPressed=true;
        }
        if(event.keyCode == Keyboard.UP || event.keyCode == 87){
            upPressed=true;
        }
        if(event.keyCode == Keyboard.DOWN || event.keyCode == 83){
            downPressed=true;
        }
    }
    private function key_up(event:KeyboardEvent): void{
        if(event.keyCode == Keyboard.LEFT || event.keyCode == 65){
            leftPressed=false;
        }
        if(event.keyCode == Keyboard.RIGHT || event.keyCode == 68){
            rightPressed=false;
        }
        if(event.keyCode == Keyboard.UP || event.keyCode == 87){
            upPressed=false;
        }
        if(event.keyCode == Keyboard.DOWN || event.keyCode == 83){
            downPressed=false;
        }
    }

Note: In another part of the code, I defined how the player moves if leftPressed, rightPressed, downPressed and upPressed is true or false.

Aucun commentaire:

Enregistrer un commentaire