Crash_Override
Crash_Override

Reputation: 368

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.

Upvotes: 3

Views: 3935

Answers (2)

LoveMeSomeCode
LoveMeSomeCode

Reputation: 3937

Also, it's a really good idea to write a wrapper for the buttons.

By this I mean: write a class that checks each button and keeps a state for the button being UP this frame and DOWN last frame, and then it can just report that the button was pushed.

This saves you having to check that every frame and maintain the state in your client code. Derive your class from IGameComponent and add it to your Game class' Component collections at runtime.

Upvotes: 1

fire.eagle
fire.eagle

Reputation: 2783

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

Upvotes: 6

Related Questions