Thanks for that, I must be missing something though. I have no experience with the Game State Management system and am trying to help a friend.
Anyway the issue is that once the screen changes, I lose control of the controller, and it defaults back to playerindex one, and I have no idea why. Here is my code on the fist screen:
| bool HandlePlayerInput(InputState input, PlayerIndex playerIndex) |
| { |
| // Look up inputs for the specified player profile. |
| KeyboardState keyboardState = input.CurrentKeyboardStates[(int)playerIndex]; |
| for (PlayerIndex idx = PlayerIndex.One; idx <= PlayerIndex.Four; idx++) |
| { |
| GamePadState gamePad = GamePad.GetState(idx); |
| if (GamePad.GetState(idx).Buttons.A == ButtonState.Pressed) |
| { |
| ControllingPlayer = idx; |
| LoadPGScreen(playerIndex); |
| } |
| } |
| |
| |
| |
| // The game pauses either if the user presses the pause button, or if |
| // they unplug the active gamepad. This requires us to keep track of |
| // whether a gamepad was ever plugged in, because we don't want to pause |
| // on PC if they are playing with a keyboard and have no gamepad at all! |
| bool gamePadDisconnected = !GamePad.GetState(Control.ControllingPlayer).IsConnected && |
| input.GamePadWasConnected[(int)playerIndex]; |
| |
| if (gamePadDisconnected) |
| { |
| MessageBoxScreen gamePadDisconectedMessageBox = |
| new MessageBoxScreen(Resources.GamepadDisconected, false); |
| ScreenManager.AddScreen(gamePadDisconectedMessageBox, playerIndex); |
| return false; |
| |
| } |
| else |
| { |
| if (GamePad.GetState(Control.ControllingPlayer).IsConnected) |
| { |
| // load PGScreen |
| if (GamePad.GetState(Control.ControllingPlayer).IsButtonDown(Buttons.A)) |
| { |
| LoadPGScreen(playerIndex); |
| } |
| } |
and the second:
| bool HandlePlayerInput(InputState input, PlayerIndex playerIndex) |
| { |
| // Look up inputs for the specified player profile. |
| KeyboardState keyboardState = input.CurrentKeyboardStates[(int)playerIndex]; |
| GamePadState gamePadState = GamePad.GetState(Control.ControllingPlayer); |
| |
| // The game pauses either if the user presses the pause button, or if |
| // they unplug the active gamepad. This requires us to keep track of |
| // whether a gamepad was ever plugged in, because we don't want to pause |
| // on PC if they are playing with a keyboard and have no gamepad at all! |
| bool gamePadDisconnected = !GamePad.GetState(Control.ControllingPlayer).IsConnected && |
| input.GamePadWasConnected[(int)playerIndex]; |
| |
| |
| if (gamePadDisconnected) |
| { |
| MessageBoxScreen gamePadDisconectedMessageBox = |
| new MessageBoxScreen(Resources.GamepadDisconected, false); |
| ScreenManager.AddScreen(gamePadDisconectedMessageBox, playerIndex); |
| return false; |
| |
| } |
| else |
| { |
| if (gamePadState.IsConnected) |
| { |
| if (GamePad.GetState(Control.ControllingPlayer).IsButtonDown(Buttons.A)) |
| { |
| loadTitleScreen(playerIndex); |
| } |
| } |