I'm writing a simple 2D platformer game on p5js, with Visual Studio Code 2022. I want to move this dinosaur sprite to the right and the left, however the keyIsDown for the right arrow doesn't work. I get no error message, and the game is always functional, and the key on the keyboard is working, but the sprite doesn't move to the right. Any ideas on how to solve this?
the code I wrote: code image
Two answers:
You could use the function keyIsPressed(LEFT_ARROW)
You could have a separate function keyIsDown() outside of the draw function.
function keyIsDown(){
if(key == LEFT_ARROW){
doTheDinoStuff();
}
}