示例#1
0
 /// <summary>
 /// Helper for checking if a key was 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 IsKeyPressed(Keys key, PlayerIndex?controllingPlayer, out PlayerIndex playerIndex)
 {
     if (controllingPlayer.HasValue)
     {
         playerIndex = controllingPlayer.Value;
         return(CurrentKeyboardStates.IsKeyDown(key));
     }
     else
     {
         // Accept input from any player.
         return(IsKeyPressed(key, PlayerIndex.One, out playerIndex) ||
                IsKeyPressed(key, PlayerIndex.Two, out playerIndex) ||
                IsKeyPressed(key, PlayerIndex.Three, out playerIndex) ||
                IsKeyPressed(key, PlayerIndex.Four, out playerIndex));
     }
 }
示例#2
0
        /// <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;

                return(CurrentKeyboardStates.IsKeyDown(key) && LastKeyboardStates.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));
            }
        }