Game Development Reference
In-Depth Information
framework to work with. It takes care of some stuff behind the scenes for us, while
still allowing us to leverage the full power of DirectX.
The Update() method
Now, we are going to add an Update() method to our user input class. This method
will be called once per frame to get the latest user input data. We will be calling this
method from the UpdateScene() method in our GameWindow class. Here is the
code:
public void Update()
{
// Reacquire the devices in case another
application has
// taken control of them.
m_Keyboard.Acquire();
m_Mouse.Acquire();
// Update our keyboard state variables.
m_KeyboardStateLast = m_KeyboardStateCurrent;
m_KeyboardStateCurrent =
m_Keyboard.GetCurrentState();
// Update our mouse state variables.
m_MouseStateLast = m_MouseStateCurrent;
m_MouseStateCurrent =
m_Mouse.GetCurrentState();
}
The first two lines of code reacquire the keyboard and mouse devices in case an-
other application has taken control of them since the previous frame. We have to
acquire the mouse and keyboard devices so that our program has access to them.
As long as the device is acquired, DirectInput makes its data available to our pro-
gram. Acquiring the device is not permanent however, which is why we do it at the
beginning of the UpdateScene() method. This ensures that we have access to the
keyboard and mouse devices before we try to use them in the next lines of code.
Search WWH ::




Custom Search