0
Why don't the keys work? JavaScript
When I ran this on browser while making the game the player would move around normally wthout a problem, after copy pasting the code in SoloLearn it wouldn't work however: https://code.sololearn.com/Wa1603A8A0a1
2 odpowiedzi
+ 1
Add tabindex="0" as attribute to the canvas tag.
Add canvas.focus() to your script.
And finally add preventDefault() method to the keyDown and keyUp event handlers.
https://code.sololearn.com/Wa7A18a29A24/?ref=app
+ 1
Karak10,
Error Line 10-11
Was having minor syntax error
canvas.width = window.innerWidthl
canvas.height = window.innerHeight;
It should be as
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
It's works fine with this change.
Any way I don't know how to play game this fix will keep it working.
DHANANJAY