Game Development Reference
In-Depth Information
m_Joy1StateLast = m_Joy1StateCurrent;
m_Joy1StateCurrent =
m_Joystick1.GetCurrentState();
As we did with the mouse and keyboard, we do with our
Joystick
object too. We
take the value of the
m_Joy1StateCurrent
member variable and copy it into the
m_Joy1StateLast
variable since this state data is now one frame old. Then we get
the current joystick state and store it in the
m_Joy1StateCurrent
member vari-
able.
Our user input class now supports the use of one joystick. You could support more
by adding variables and code for the second joystick the same way we did for this
first joystick. Now, let's add some test code at the end of the
Update()
method to
see this in action:
if (m_Joy1StateCurrent.IsPressed(0))
System.Diagnostics.Debug.WriteLine("DIRECTINPUT:
BUTTON 0 IS PRESSED!");
if (m_Joy1StateCurrent.IsPressed(1))
System.Diagnostics.Debug.WriteLine("DIRECTINPUT:
BUTTON 1 IS PRESSED!");
if (m_Joy1StateCurrent.IsPressed(2))
System.Diagnostics.Debug.WriteLine("DIRECTINPUT:
BUTTON 2 IS PRESSED!");
if (m_Joy1StateCurrent.IsPressed(3))
System.Diagnostics.Debug.WriteLine("DIRECTINPUT:
BUTTON 3 IS PRESSED!");