> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/flatredball/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/flatredball/api/flatredball/input/xbox360gamepad.md).

# Xbox360GamePad

### Introduction

The Xbox360GamePad class represents the current state of a physical game pad. The Xbox360GamePad can provide information about its buttons and DPad with ButtonPushed, ButtonDown, and ButtonReleased methods. You can also get information about the analog sticks using the [AnalogSticks](/flatredball/api/flatredball/input/analogstick.md) references. Information about the trigger buttons can be accessed through the [AnalogButton](/flatredball/api/flatredball/input/analogbutton.md) references. The [InputManager](/flatredball/api/flatredball/input/inputmanager.md) exposes an array of Xbox360GamePads. There are always 4 elements in this array regardless of the number of game pads connected.

### Xbox360GamePad and Gamepad Hardware

The name Xbox360GamePad exists for historical reasons - XNA originally only exposed support for Xbox36 controllers. Modern versions of FlatRedBall provide support for a variety of hardware including:

* Xbox360 and Xbox One controllers
* Switch Pro controllers
* USB Gamecube controllers
* Playstation DualShock
* General PC controllers

### Detecting Button Presses

The Xbox360GamePad class reports whether a button was pushed the last frame, is currently down, or was released. The following code moves a [Sprite](/flatredball/api/flatredball/sprite.md) to the right one unit when the A button is pressed and moves a [Sprite](/flatredball/api/flatredball/sprite.md) to the left when the B button is released:

```csharp
// Assuming mySprite is a valid Sprite
Xbox360GamePad gamePad = InputManager.Xbox360GamePads[0];
if(gamePad.ButtonPushed(Xbox360GamePad.Button.A))
{
   mySprite.X += 32;
}
if(gamePad.ButtonReleased(Xbox360GamePad.Button.B))
{
   mySprite.X -= 32;
}
```

### Detecting Connected Gamepads

The following code reports the number of game pads connected at a given time:

```csharp
 int numberConnected = 0;

 for(int i = 0; i < InputManager.Xbox360GamePads.Length; i++)
 {
     if(InputManager.Xbox360GamePads[i].IsConnected)
         numberConnected++;
 }
```

### Using the Analog Sticks

The Xbox360GamePad provides two analog sticks:

* LeftStick
* RightStick

Each property provides information about the matching hardware analog stick. For more information on using the analog stick property, see the [AnalogStick](https://github.com/flatredball/FlatRedBallDocs/tree/main/documentation/api/flatredball/input/analogstick.md) page.

### Using a Keyboard as a Game Pad

See the [ButtonMap property](/flatredball/api/flatredball/input/xbox360gamepad/buttonmap.md).

### Vibrations

The following code sets the vibration on the game pad:

```csharp
 // Values should fall between 0.0f and 1.0f
 float leftMotor = .2f; // the low-frequency motor
 float rightMotor = .2f; // the high-frequency motor

 InputManager.Xbox360GamePads[0].SetVibration(leftMotor, rightMotor);
```

### Frequency of Updates

The Xbox360GamePads which are part of the [InputManager](/flatredball/api/flatredball/input/inputmanager.md) are automatically updated every frame by the engine. This information is not buffered, therefore very rapid button presses may not be ready by the controller.

### Platform Support

The Xbox360GamePad name orignally comes from the fact that XNA supported Xbox 360 controllers. Despite its name, the Xbo360GamePad class can be used on most FlatRedBall platforms. As of the time of this writing, the following platforms and hardware are supported.

* Desktop GL: Xbox 360 controllers, Xbox One controllers, Switch Pro controllers, USB Gamecube controllers, PlayStation DualShock, Generic PC controllers
* Desktop XNA: Xbox 360 controllers, Xbox One controllers
* Android: Bluetooth and wired controllers
* iOS: Untested

###


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flatredball.com/flatredball/api/flatredball/input/xbox360gamepad.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
