Game Development Reference
In-Depth Information
downPtrTrigger->SetData(nullptr, &downBounds,
KeyState::Pressed);
// ...
_actionMoveUp = im->CreateAction();
auto upPadTrigger =
_actionMoveUp->CreateTrigger<GamepadButtonTrigger>();
upPadTrigger->SetData(GamepadButtons::DPad_Up,
KeyState::Pressed);
Once we have created the actions with
InputManager
, it's just two lines to create a
new trigger based on the type we want and set the desired data. In the first example,
we use
AxisBounds
created earlier to define a
PointerAxisBoundsTrigger
, for
which we just define the Y axis, passing
nullptr
to the X axis.
For the second action we have example code for setting a
GamepadButtonTrig-
ger
, which is very similar to the
KeyTrigger
, as you just saw.
We can now fill out the
Update
method:
void Player::Update(float deltaTime)
{
if (_actionMoveDown->IsTriggered())
{
Move(ShipDirection::Down, deltaTime);
}
else if(_actionMoveUp->IsTriggered())
{
Move(ShipDirection::Up, deltaTime);
}
}
Based on the state of each action we simply call the
Move
helper command to move
up or down as required. Of course don't forget to hook up the
InputManager
to
each of the
Key
and
Pointer
events in
Game.cpp
.