Chapter 5. Give Me Your Input
WHAT'S IN THIS CHAPTER?
Building your own input management system
Mapping multiple sources of control input to the same actions
When developing games for multiple target platforms, you will quickly run into scenarios where your game requires several different ways to perform the same action based on the limitations of the individual platforms. The opposite can happen when you're developing a single-platform game. As your game gets progressively more screen states (and correspondingly more complex), you may find yourself needing to map different game actions to the same button, based on the active screen.
No matter which of these situations you find yourself in, there is a very simple answer. As described in this chapter, a properly designed input management system provides the freedom to map any number of actions to a single control and to map multiple controls to a single action.
BUILDING THE INPUT MANAGEMENT SYSTEM
The first step when creating an input management system is to disconnect individual actions from the control inputs that cause them. This allows you to map multiple input types to a single action and also makes it easier to change mappings (if necessary) from one screen to the next.
The purpose of the
Input class is to store information about each input type that you will define in your game. This class will be used in the
Inputs collection in the
GameInput class defined later in this chapter.
The complete code for this project is available ...