(7/8/2013 - This Unit is still a work-in-progress. The code needs explanation and the Demo and TestCode are not complete)


Expect this Unit to last between 1 to 2 hours. To demonstrate what you should have at the end of this Unit, check out the Demo for Unit 7.

There's a number of different ways users can interact with your game. For web games it's usually keyboard and/or mouse. Mobile and tables are typically just touch screen. You might be surprised to hear that some browsers support gamepad controllers! What about extra hardware features like gyros and tilt sensors? The WiiU has lots of extra input features, so how might we build a system that has room for addition input devices down the road? Creating a good encapsulation for input that can handle this diversity of devices is super important for games these days!

In this unit we'll talk about how to create an abstraction between game events and input events, and build in support for a few different input mechanisms. With these you should be able to easily extend the system to handle touch input:

We'll also be doing something new here. Input is going to be it's own sub system, and not a set of functions we append to the Engine directly.

Input System

Source Code:

Keyboard Input

Keyboard constants

Source Code:

Keyboard API & Implementation

Source Code:

Mouse Input

Mouse constants

Source Code:

Mouse API & Implementation

Source Code:

Gamepad Input

Gamepad constants

Source Code:

Gamepad API & Implementation

Source Code:

Test Code

Source Code:


Part 1. Create and add input.js to your project:

Part 2. Fill out input.js with the code from this Unit.