I have a menu that you can navigate with the keyboard, but I also want it so you can navigate it with the controller thumb sticks. But my problem is that if you push down or up on the thumb sticks it will just fly through the menu. To fix problem if it was a keyboard you would just do: prevKeyState.IsKeyUp(Keys.Down)
.
So I was wondering if there anything like this for the controller thumb sticks?
I'm not sure if I'm doing something wrong but it still flies through the menu.
private enum GamePadStates
{
None,
GoingDown,
GoingUp
}
GamePadStates CurrentGamePad, PreviousGamePad = GamePadStates.None;
public void Update(GameTime gameTime)
{
keyState = Keyboard.GetState();
gamePadState = GamePad.GetState(PlayerIndex.One);
PreviousGamePad = CurrentGamePad;
if (gamePadState.ThumbSticks.Left.Y > 0.1)
CurrentGamePad = GamePadStates.GoingUp;
else if (gamePadState.ThumbSticks.Left.Y < -0.1)
CurrentGamePad = GamePadStates.GoingDown;
else
CurrentGamePad = GamePadStates.None;
if (keyState.IsKeyDown(Keys.Down) && prevKeyState.IsKeyUp(Keys.Down) ||
CurrentGamePad == GamePadStates.GoingDown && PreviousGamePad != GamePadStates.GoingUp)
{
if (selected < (buttonList.Count - 1))
{
selected++;
}
}
if (keyState.IsKeyDown(Keys.Up) && prevKeyState.IsKeyUp(Keys.Up) ||
CurrentGamePad == GamePadStates.GoingUp && PreviousGamePad != GamePadStates.GoingDown)
{
if (selected > 0)
{
selected--;
}
}