0

So I'm trying to do something quite simple using a gamepad that I have done using a keyboard before. And that is to create an old state to record what button was pressed on the last update.

So when using the keyboard I had a code that looked something like this:

oldKeyboard = currentKeyboard;

This was placed at the end of my update and meant that on the next update I could have if statements like such

if (currentKeyboard.IsKeyDown(Keys.A) &&(oldKeyboard.IsKeyUp(Keys.A))
{
guy.drawRect.X ++;
}

The problem I'm having now is that I'm using a Xbox Gamepad in my code and I just don't know what the correct code is. Currently this is what I have and it isn't working :P. Any help would be greatly appreciated.

 void ShipUpdate(GamePadState Curr, GamePadState Old)
    {
        Curr = GamePad.GetState(PlayerIndex.One);

        if (Old.ThumbSticks.Left.X > 0.0f && (Curr.ThumbSticks.Left.X == 0.0f))
        {
            move = MoveState.Still;
            guy.srcRect.X = 0;
        }

        Old = Curr;


    }

I've stripped all non essential code here so this is J.E.E.P

Gandeh
  • 141
  • 1
  • 1
  • 5
  • I managed to fix this issue myself. The key was in the following line void ShipUpdate(GamePadState Curr, GamePadState Old) Once I removed the gamepad states from these line everything worked just fine. Here is the corrected line. void ShipUpdate() – Gandeh Jun 02 '13 at 19:02

1 Answers1

0

You are not actually updating your old state. Since you are passing those as arguments and the GamePadState is actually a structure,

 Old = Curr;

updates only the local copy of the 'old' variable. Pass them by reference like

 void ShipUpdate(ref GamePadState Curr, ref GamePadState Old)
Nikola Dimitroff
  • 6,127
  • 2
  • 25
  • 31