Game Development Reference
In-Depth Information
{
_joystick = joystick;
_index = index;
}
public void Update()
{
byte b = Sdl.SDL_JoystickGetHat(_joystick, _index);
UpHeld = (b == Sdl.SDL_HAT_UP);
DownHeld = (b == Sdl.SDL_HAT_DOWN);
LeftHeld = (b == Sdl.SDL_HAT_LEFT);
RightHeld = (b == Sdl.SDL_HAT_RIGHT);
}
}
}
The controller only has one D-pad, but it still needs to be added.
public DPad Dpad { get; private set; }
public XboxController(int player)
{
_joystick = Sdl.SDL_JoystickOpen(player);
Dpad = new DPad(_joystick, 0);
// ... later in the code
public void Update()
{
Dpad.Update();
The D-pad also needs to be added to the update loop, and that completes all the
controls on the controller. Finally, it can be visualized by reusing the button
display code.
DrawButtonPoint(_controller.Dpad.UpHeld, 80);
DrawButtonPoint(_controller.Dpad.DownHeld, 60);
DrawButtonPoint(_controller.Dpad.LeftHeld, 40);
DrawButtonPoint(_controller.Dpad.RightHeld, 20);
All the controls of the Xbox 360 controller are now supported and it's relatively
easy to construct any other type of controller from these control pieces. The con-
troller is quite easy to use, but the buttons could do with a little more work. At the
moment, the button reports if it is held down or not; in games it's often more
 
Search WWH ::




Custom Search