protected override void Update(GameTime gameTime)
{
if (Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit();
// Check the device for Player One
GamePadCapabilities capabilities = GamePad.GetCapabilities(PlayerIndex.One);
// If there a controller attached, handle it
if (capabilities.IsConnected)
{
// Get the current state of Controller1
//GamePadState state = GamePad.GetState(PlayerIndex.One);
GamePadState state = GamePad.GetState(PlayerIndex.One, GamePadDeadZone.Circular);
// You can check explicitly if a gamepad has support for a certain feature
if (capabilities.HasLeftXThumbStick)
{
// Check teh direction in X axis of left analog stick
if (state.ThumbSticks.Left.X < -0.5f)
position.X -= 10.0f;
if (state.ThumbSticks.Left.X > 0.5f)
position.X += 10.0f;
}
// You can also check the controllers "type"
if (capabilities.GamePadType == GamePadType.GamePad)
{
if (state.IsButtonDown(Buttons.A))
Exit();
}
}
base.Update(gameTime);
}