Now that we have our main game objects in place, we need to hand some control over to the user. In this chapter we’ll do this using keyboard events. In JavaScript, you can use many events to control your program. We use events by defining an event handler (a function) that will be called with the event object as an argument when the event is triggered. In this case, we’ll be using keyboard events—in particular, the keyDown and keyUp events. These are called when keys are pressed and released. The event object contains information about which ...
© Graeme Stuart 2017
Graeme Stuart, Introducing JavaScript Game Development , https://doi.org/10.1007/978-1-4842-3252-1_10
10. Simple Keyboard Interaction
Graeme Stuart1
(1)Market Harborough, Leicestershire, UK
Get Introducing JavaScript Game Development : Build a 2D Game from the Ground Up now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.