Game Development Reference
In-Depth Information
Here we're just passing the VirtualKey code through to the KeyUp() and
KeyDown() methods that we need to add to the Game object.
Inside the Game class, we will define the following prototypes:
void KeyDown(Windows::System::VirtualKey vkey);
void KeyUp(Windows::System::VirtualKey vkey);
Now we can move onto the interesting part. Inside the Game.cpp file, we need to
add the following code:
void Game::KeyDown(Windows::System::VirtualKey
vkey)
{
switch (vkey)
{
case Windows::System::VirtualKey::Left:
case Windows::System::VirtualKey::Up:
_sidePressed = -1;
break;
case Windows::System::VirtualKey::Right:
case Windows::System::VirtualKey::Down:
_sidePressed = 1;
break;
}
}
void Game::KeyUp(Windows::System::VirtualKey
vkey)
{
_sidePressed = 0;
}
In this code, the KeyUp() method is exactly the same as the PointerReleased
handler; however, the real work is done in the KeyDown() method. We'll rely on the
Update() method that we implemented earlier to handle the movement logic so
Search WWH ::




Custom Search