/// <summary> /// Evaluates the action against a given InputState. /// </summary> /// <param name="state">The InputState to test for the action.</param> /// <param name="controllingPlayer">The player to test, or null to allow any player.</param> /// <param name="player">If controllingPlayer is null, this is the player that performed the action.</param> /// <returns>True if the action occurred, false otherwise.</returns> public bool Evaluate(InputState state, PlayerIndex? controllingPlayer, out PlayerIndex player) { // Figure out which delegate methods to map from the state which takes care of our "newPressOnly" logic ButtonPress buttonTest; KeyPress keyTest; MouseButtonPress mouseTest; if (newPressOnly) { buttonTest = state.IsNewButtonPress; keyTest = state.IsNewKeyPress; mouseTest = state.IsNewMouseButtonPress; } else { buttonTest = state.IsButtonPressed; keyTest = state.IsKeyPressed; mouseTest = state.IsMouseButtonPressed; } // Now we simply need to invoke the appropriate methods for each button and key in our collections foreach (Buttons button in buttons) { if (buttonTest(button, controllingPlayer, out player)) return true; } foreach (Keys key in keys) { if (keyTest(key, controllingPlayer, out player)) return true; } foreach (MouseButtons mouseButton in mouseButtons) { if (mouseTest(mouseButton, controllingPlayer, out player)) return true; } // If we got here, the action is not matched player = PlayerIndex.One; return false; }
/// <summary> /// Responds to user input, accepting or cancelling the message box. /// </summary> public override void HandleInput( GameTime gameTime, InputState input) { //PlayerIndex playerIndex; if ((input.IsNewKeyRelease(Microsoft.Xna.Framework.Input.Keys.Space)) || (input.IsNewKeyRelease(Microsoft.Xna.Framework.Input.Keys.Enter)) || (input.IsNewKeyRelease(Microsoft.Xna.Framework.Input.Keys.Escape)) || (input.MouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) || (input.MouseState.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) ) { screenFinished = true; } }
public override void HandleInput(GameTime gameTime, InputState input) { base.HandleInput( gameTime, input); }