本文整理汇总了C#中GameStateManagement.InputState类的典型用法代码示例。如果您正苦于以下问题:C# InputState类的具体用法?C# InputState怎么用?C# InputState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InputState类属于GameStateManagement命名空间,在下文中一共展示了InputState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleInput
public override void HandleInput(GameTime gameTime, InputState input)
{
KeyboardState keyboardState = input.CurrentKeyboardState;
KeyboardState lastKeyboardState = input.LastKeyboardState;
if ((keyboardState.IsKeyDown(Keys.Up) && !lastKeyboardState.IsKeyDown(Keys.Up)) || (keyboardState.IsKeyDown(Keys.W) && !lastKeyboardState.IsKeyDown(Keys.W)))
{
selectedEntry--;
if (selectedEntry < 0)
selectedEntry = menuEntries.Count - 1;
}
if (keyboardState.IsKeyDown(Keys.Down) && !lastKeyboardState.IsKeyDown(Keys.Down) || (keyboardState.IsKeyDown(Keys.S) && !lastKeyboardState.IsKeyDown(Keys.S)))
{
selectedEntry++;
if (selectedEntry >= menuEntries.Count)
selectedEntry = 0;
}
if ((keyboardState.IsKeyDown(Keys.Space) && !lastKeyboardState.IsKeyDown(Keys.Space)) || (keyboardState.IsKeyDown(Keys.Enter) && !lastKeyboardState.IsKeyDown(Keys.Enter)))
{
OnSelectEntry(selectedEntry);
}
else if (keyboardState.IsKeyDown(Keys.Escape) && !lastKeyboardState.IsKeyDown(Keys.Escape))
{
OnCancel();
}
}
示例2: Evaluate
/// <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 occured, 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;
if (newPressOnly)
{
buttonTest = state.IsNewButtonPress;
keyTest = state.IsNewKeyPress;
}
else
{
buttonTest = state.IsButtonPressed;
keyTest = state.IsKeyPressed;
}
// 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;
}
// If we got here, the action is not matched.
player = PlayerIndex.One;
return false;
}
示例3: HandleInput
public override void HandleInput(AxiosGameScreen gameScreen, InputState input, GameTime gameTime)
{
base.HandleInput(gameScreen, input, gameTime);
//if (gameScreen.Console != null && gameScreen.Console.Active)
// return;
PlayerIndex p;
Animate = false;
if (input.IsKeyPressed(Keys.A, PlayerIndex.One, out p))
{
Move(Direction.Left);
}
if (input.IsKeyPressed(Keys.W, PlayerIndex.One, out p) && !jumping)
{
Move(Direction.Up);
jumping = true;
}
//else if (input.IsKeyPressed(Keys.S, PlayerIndex.One, out p))
//{
// Move(Direction.Down);
//}
if (input.IsKeyPressed(Keys.D, PlayerIndex.One, out p))
{
Move(Direction.Right);
}
else
{
//BodyPart.LinearVelocity = Vector2.Zero;
}
}
示例4: HandleInput
public override void HandleInput(InputState input)
{
if (isLoading == true)
{
base.HandleInput(input);
return;
}
foreach (var gesture in input.Gestures)
{
if (gesture.GestureType == GestureType.Tap)
{
// Create a new instance of the gameplay screen
gameplayScreen = new GameplayScreen();
gameplayScreen.ScreenManager = ScreenManager;
// Start loading the resources in additional thread
thread = new System.Threading.Thread(
new System.Threading.ThreadStart(gameplayScreen.LoadAssets));
isLoading = true;
thread.Start();
}
}
base.HandleInput(input);
}
示例5: OnInput
public override void OnInput(InputState input)
{
Keys[] pressedKeys = input.NewPressedKeys().ToArray();
for (int i = pressedKeys.Length - 1; i >= 0; i--)
{
Keys pressedKey = pressedKeys[i];
int pressedKeyNum = (int)pressedKey;
if (pressedKey >= Keys.A && pressedKey <= Keys.Z)
{
Value += (char)((input.IsKeyPressed(Keys.LeftShift) || input.IsKeyPressed(Keys.RightShift)) ? pressedKeyNum : pressedKeyNum + 32);
}
else if (pressedKey == Keys.Space) Value += " ";
else if (pressedKey == Keys.Back && Value.Length > 0) Value = Value.Substring(0, Value.Length - 1);
//if (input.Mapping.Chars().ContainsKey(pressedKey)) Value += input.IsKeyPress(input.Mapping.Shift) ? input.Mapping.Chars()[pressedKey] : (char)(input.Mapping.Chars()[pressedKey] + 32);
//else if (input.Mapping.Numbers().ContainsKey(pressedKey)) Value += input.Mapping.Numbers()[pressedKey].ToString();
//else if (pressedKey == input.Mapping.Hyphen || pressedKey == Key.Minus) Value += input.IsKeyPress(Key.ShiftLeft) ? "_" : "-";
//else if (pressedKey == input.Mapping.Point) Value += input.IsKeyPress(Key.ShiftLeft) ? ":" : ".";
//else if (pressedKey == input.Mapping.Comma) Value += input.IsKeyPress(Key.ShiftLeft) ? ";" : ",";
//else if (pressedKey == input.Mapping.Space) Value += " ";
//else if (pressedKey == input.Mapping.Back && Value.Length > 0) Value = Value.Substring(0, Value.Length - 1);
}
base.OnInput(input);
}
示例6: HandleInput
/// <summary>
/// Lets the game respond to player input. Unlike the Update method,
/// this will only be called when the gameplay screen is active.
/// </summary>
public override void HandleInput(InputState input)
{
if (input == null)
throw new ArgumentNullException("input");
// Look up inputs for the active player profile.
int playerIndex = (int)ControllingPlayer.Value;
KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex];
GamePadState gamePadState = input.CurrentGamePadStates[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 = !gamePadState.IsConnected && input.GamePadWasConnected[playerIndex];
if (input.IsPauseGame(ControllingPlayer) || gamePadDisconnected)
{
ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer);
}
else
{
xspace.HandleInput(keyboardState, gamePadState);
}
}
示例7: HandleInput
/// <summary>
/// Lets the game respond to player input. Unlike the Update method,
/// this will only be called when the main menu screen is active.
/// </summary>
public override void HandleInput(InputState input)
{
if (input == null)
throw new ArgumentNullException("input");
base.HandleInput(input);
}
示例8: HandleInput
public override void HandleInput(GameTime gameTime, InputState input)
{
// Read in our gestures
foreach(GestureSample gesture in input.Gestures) {
if (single) { // if it is single player, just start the game
if(Configuration.GAME_TEST) {
SwitchScreen(Configuration.DEF_GAME);
} else {
SwitchScreen(game.ScreenType);
}
return;
}
if (gesture.GestureType == GestureType.Tap && !done) {
done = true;
text = "Waiting for other players...";
Sync((JArray data, double rand) => {
timeLeftTimer.Dispose(); // dispose of the timer so we don't decrement the time anymore
if(Configuration.GAME_TEST) {
SwitchScreen(Configuration.DEF_GAME);
} else {
SwitchScreen(game.ScreenType);
}
}, "tutorial", 13); // give other players 13 seconds to continue
}
}
base.HandleInput(gameTime, input);
}
示例9: HandleInput
public override void HandleInput(InputState input)
{
if (input == null)
{
throw new ArgumentNullException("input");
}
//Go back to the previous screen if the player presses the back button
if (input.IsPauseGame(null))
{
Exit();
}
// Return to the main menu when a tap gesture is recognized
if (input.Gestures.Count > 0)
{
GestureSample sample = input.Gestures[0];
if (sample.GestureType == GestureType.Tap)
{
Exit();
input.Gestures.Clear();
}
}
}
示例10: HandleInput
public override void HandleInput(InputState input)
{
base.HandleInput(input);
for (int i = 0; i < 6; i++)
{
if (Settings.players[i].active == false && input.IsPlayerTurnLeft((PlayerNumber)i))
{
Settings.players[i].active = true;
Settings.Game.num_players++;
}
else if (Settings.players[i].active == true && input.IsPlayerTurnRight((PlayerNumber)i))
{
Settings.players[i].active = false;
Settings.Game.num_players--;
}
}
if (Settings.Game.num_players > 1 && input.MenuSelect)
{
LoadingScreen.Load(ScreenManager, true, new GamePlayScreen());
ExitScreen();
}
if (input.PauseGame)
{
const string message = "Are you sure you want to quit this game?";
MessageBoxScreen confirmQuitMessageBox = new MessageBoxScreen(message);
confirmQuitMessageBox.Accepted += ConfirmQuitMessageBoxAccepted;
ScreenManager.AddScreen(confirmQuitMessageBox);
}
}
示例11: HandleInput
public override void HandleInput(InputState input)
{
PlayerIndex player;
if (input.IsNewButtonPress(Buttons.Y, ControllingPlayer, out player))
{
#if XBOX
Debug.Assert (ControllingPlayer != null);
HighScores2.GoLoad(ControllingPlayer ?? PlayerIndex.One);
#else
HighScores2.DoWindowsLoadGame();
#endif
ScreenManager.AddScreen(new HighScoreScreen(), ControllingPlayer);
}
if (input.IsMenuCancel(ControllingPlayer, out player))
{
MediaPlayer.Stop();
}
songSelectionBox.HandleInput(input);
if (songSelectionBox.SongCount <= 0 &&
input.IsNewButtonPress(Buttons.A, null, out player))
{
return;
}
base.HandleInput(input);
}
示例12: Evaluate
public bool Evaluate(InputState state, PlayerIndex? controllingPlayer, out PlayerIndex player)
{
ButtonPress buttonTest;
KeyPress keyTest;
if (newPressOnly)
{
buttonTest = state.IsNewButtonPress;
keyTest = state.IsNewKeyPress;
}
else
{
buttonTest = state.IsButtonPressed;
keyTest = state.IsKeyPressed;
}
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;
}
player = PlayerIndex.One;
return false;
}
示例13: Button
/// <summary>
/// Creates a new instance of the <see cref="Button"/> class.
/// </summary>
/// <param name="regularTexture">The name of the button's texture.</param>
/// <param name="pressedTexture">The name of the texture to display when the
/// button is pressed.</param>
/// <param name="input">A <see cref="GameStateManagement.InputState"/> object
/// which can be used to retrieve user input.</param>
/// <param name="cardGame">The associated card game.</param>
/// <remarks>Texture names are relative to the "Images" content
/// folder.</remarks>
public Button(string regularTexture, string pressedTexture, InputState input,
CardsGame cardGame)
: base(cardGame, null)
{
this.input = input;
this.regularTexture = regularTexture;
this.pressedTexture = pressedTexture;
}
示例14: ScreenManager
/// <summary>
/// Constructs a new screen manager component.
/// </summary>
public ScreenManager(Game game)
: base(game)
{
// we must set EnabledGestures before we can query for them, but
// we don't assume the game wants to read them.
TouchPanel.EnabledGestures = GestureType.None;
this.input = new InputState(this);
}
示例15: HandleInput
public override void HandleInput(InputState input)
{
// look for any taps that occurred and select any entries that were tapped
foreach (GestureSample gesture in input.Gestures)
{
//check against the panel
}
base.HandleInput(input);
}