Question

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

Était-ce utile?

La solution

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)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top