Search code examples
c#xnaxbox360

XNA C# Controller Input Structures


I have looked all over the net and need some assistance. Is there a link somewhere to example code of all the buttons for the Xbox 360 controller. For example:

if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
    this.Exit();

I know this exits the game if you press back on the controller.

I just need examples of states for both joysticks, d-pad, and all the buttons.


Solution

  • Have you checked out the MSDN XNA input documentation? It doesn't really have examples, but it appears you have the idea of what you do with the inputs.

    The articles there have all the information on the inputs.

    All the controller buttons which you can get to through GamePad.GetState(PlayerIndex.One).Buttons

    The joystick which you can get through GamePad.GetState(PlayerIndex.One).Thumbsticks

    And the D-Pad which you can get through GamePad.GetState(PlayerIndex.One).DPad