Game Development Reference
In-Depth Information
Mouse m_Mouse;
MouseState m_MouseStateCurrent;
MouseState m_MouseStateLast;
Wehaveahandfulofmembervariableshere.Thefirstoneis m_IsDisposed ,which
has the same purpose as the m_IsDisposed member variable that we created in
our GameWindow class. The second variable, m_DirectInput , will hold our Dir-
ectInput object.
Next, we have a group of three variables. The first one, m_Keyboard , holds the
keyboard object. The next two keep track of the current and previous state of the
keyboard. So, m_KeyboardStateCurrent holds the keyboard state for the current
frame while m_KeyboardStateLast holds the keyboard state from the previous
frame. Why do we need both? This is necessary, for example, if you want to detect
whether or not the user is holding down a key, rather than simply pressing it.
Next, we have a set of three very similar variables for our mouse object and
our current and previous mouse state ( m_Mouse , m_MouseStateCurrent , and
m_MouseStateLast ).
The constructor
Now, we need to create our constructor to initialize our user input object. Here is the
code to do so:
public UserInput()
{
InitDirectInput();
m_KeyboardStateCurrent = new KeyboardState();
m_KeyboardStateLast = new KeyboardState();
m_MouseStateCurrent = new MouseState();
m_MouseStateLast = new MouseState();
}
Search WWH ::




Custom Search