Game Development Reference
In-Depth Information
devices, including ways to pass through the key and pointer events that we saw in
the last chapter.
For the implementation of InputManager , I'll leave it as an exercise to the reader to
implement the singleton and input device functionality. Refer to the previous chapter
or the sample code for a reference implementation.
void InputManager::Update()
{
UpdateGamePad();
for (auto action : _actions)
{
if (action->enabled)
action->Update(this);
}
}
The Update method in the InputManager defines the start of the input processing,
and begins by updating the GamePad, which is not an event based system. From
there it processes all of the enabled actions to update the state of the input system.
UpdateGamePad simply runs a cut down version of the gamepad state code in
Chapter 3 , Adding the Input . Here we store state for each of the connected
gamepads and don't do any other processing, instead leaving that to the trigger and
the game code.
With all of this together we just need to define triggers, which provide the code to
check if an input has triggered, and we will be able to use the input system for our
player object.
Triggers
The triggers allow us to customize different input systems and styles based on the
raw input data. This way we could define gestures for touch input or multiple button
presses to trigger a single action. We'll start simple and just work with a single key-
press trigger, which will be called KeyTrigger :
Search WWH ::




Custom Search