Add keyboard controls.
- [Instructor] Hello and welcome to video 4.2.…In this video, we are gonna add keyboard controls.…We're gonna take a look at capturing keyboard click events,…adding actions to specific keyboard click events,…and avoiding cases in which the mouse cursor location…overrides keyboard events.…In the previous video, we've added…mouse controls to the game.…Now we want to add similar controls using the keyboard…so that the game will be playable by mouse or by keyboard.…
Unlike mouse events, which are based on the location…of the mouse cursor, keyboard events work differently.…The stage listens to keyboard events…and get a keycode for the key pressed.…What we need to do is listen to specific keycodes…which we need for the movement of the paddle,…so we need the keycode for the left arrow,…the keycode for the right arrow and the spacebar.…
Now these values are: keycode left is 37;…keycode right is 39;…and the spacebar is 32.…Now keyboard events start when a key is pressed…and are also called when a key is let go.…So in order to know if the paddle needs to move left…
Note: This course was created by Packt Publishing. We are pleased to host this training in our library.
- Playing sounds in various browsers using SoundJS
- Tweening objects using TweenJS
- Creating graphic assets and basic animations
- Game stage creation and object positioning
- Adding the basic game logic
- Add the game physics
- Adding mouse and keyboard controls
- Debugging with breakpoints in Chrome
- Debugging on Android and iOS
- Character movement and input handling