O'Reilly logo

Game Development with SlimDX by Michael Fontanini

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using joysticks with XInput

Once again, we first need to add some member variables for our XInput device. They look a bit different this time, but here they are:

Controller m_Controller1;
Gamepad m_Controller1StateCurrent;
Gamepad m_Controller1StateLast;

In XInput, we use the Controller class to represent a controller. The Gamepad structure stores the state of the controller. As before, we have one variable to hold our device, and two more to hold its current and previous state.

Now, we will add a very short new method named InitXInput(). Here is its code:

private void InitXInput()
{
  m_Controller1 = new Controller(UserIndex.One);
}

This code sets up one XInput controller for us to use. We pass into its constructor the value UserIndex.One to indicate ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required