jeudi 28 septembre 2017

how can i make a game with checkKey and if/else if statements

function checkKey(e) {
var event = window.event ? window.event : e;
console.log(event.keyCode);

    if(event = 38){
        robotArm.grab();
    } else if(event = 40){
        robotArm.drop();
    } else if(event = 37){
        robotArm.moveLeft();
    } else if(event = 39){
        robotArm.moveRight();
    }
}

Hi, My problem is that it only grabs and it doesn't care which key I press how can i make it so that only the arrow keys are used and that the arm moves from left to right and drop the block when it grabbed one?

Aucun commentaire:

Enregistrer un commentaire