Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Helper for checking if a key was newly pressed during this update. The
- /// controllingPlayer parameter specifies which player to read input for.
- /// If this is null, it will accept input from any player. When a keypress
- /// is detected, the output playerIndex reports which player pressed it.
- /// </summary>
- public bool IsNewKeyPress(Keys key, PlayerIndex? controllingPlayer,
- out PlayerIndex playerIndex)
- {
- if (controllingPlayer.HasValue)
- {
- // Read input from the specified player.
- playerIndex = controllingPlayer.Value;
- int i = (int)playerIndex;
- return (CurrentKeyboardState[i].IsKeyDown(key) &&
- LastKeyboardState[i].IsKeyUp(key));
- }
- else
- {
- // Accept input from any player.
- return (IsNewKeyPress(key, PlayerIndex.One, out playerIndex) ||
- IsNewKeyPress(key, PlayerIndex.Two, out playerIndex) ||
- IsNewKeyPress(key, PlayerIndex.Three, out playerIndex) ||
- IsNewKeyPress(key, PlayerIndex.Four, out playerIndex));
- }
- }
- /// <summary>
- /// Helper for checking if a button was newly pressed during this update.
- /// The controllingPlayer parameter specifies which player to read input for.
- /// If this is null, it will accept input from any player. When a button press
- /// is detected, the output playerIndex reports which player pressed it.
- /// </summary>
- public bool IsNewButtonPress(Buttons button, PlayerIndex? controllingPlayer,
- out PlayerIndex playerIndex)
- {
- if (controllingPlayer.HasValue)
- {
- // Read input from the specified player.
- playerIndex = controllingPlayer.Value;
- int i = (int)playerIndex;
- return (CurrentGamePadState[i].IsButtonDown(button) &&
- LastGamePadState[i].IsButtonUp(button));
- }
- else
- {
- // Accept input from any player.
- return (IsNewButtonPress(button, PlayerIndex.One, out playerIndex) ||
- IsNewButtonPress(button, PlayerIndex.Two, out playerIndex) ||
- IsNewButtonPress(button, PlayerIndex.Three, out playerIndex) ||
- IsNewButtonPress(button, PlayerIndex.Four, out playerIndex));
- }
- }
RAW Paste Data