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

Getting input from the joystick

This is all well and good, but we still can't get input from a joystick. So let's look at that now. First, we need to add three member variables for our joystick, just like we did for the mouse and keyboard. Here are the three new member variables we need to add to our UserInput.cs class:

Joystick m_Joystick1;
JoystickState m_Joy1StateCurrent;
JoystickState m_Joy1StateLast;

As before, we have a variable to hold our device object (in this case, a Joystick object), and two more variables to hold the joystick state for the current frame and for the previous frame.

Now, we need to add two lines at the bottom of our constructor to initialize the joystick state variables. As discussed earlier in this chapter, this prevents ...

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