O'Reilly logo

Professional HTML5 Mobile Game Development by Pascal Rettig

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Capturing User Input

You can’t actually make a game without giving the player some way to interact with your game. Following the same pattern as Alien Invasion built in Chapters 1 through 3, Quintus handles user input from both the keyboard and via a touch interface. Supporting the keyboard is useful in development as well as when players play your game via the desktop.

Creating an Input Subsystem

The simplest way to do input is to directly bind some action (for example, pressing the right arrow key) to an action in the game, like moving the player to the right. The problem with this mechanism becomes obvious after you add additional input options to your game.

In the case of a game that needs to work on both mobile and desktop, you have at least two input mechanisms: keyboard or mouse and touch. Abstracting your game logic away from what’s actually generating the input and providing a consistent interface to the engine can make developing games much easier.

Quintus uses a module called Quintus.Input to handle input. Keeping the input code separate from the rest of the Quintus engine helps keep the dependencies in check and makes it easier to swap out a different input engine if necessary.

The input module will eventually support five different input mechanisms:

  • Keyboard (desktop input)
  • Mouse (desktop input)
  • Direct manipulation (touch input)
  • Keypad (touch input)
  • Joypad (touch input)

Keyboard and mouse hopefully need no extra description. Direct manipulation refers to the capability ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required