本文整理汇总了C#中Microsoft.Xna.Framework.Input.GamePadState类的典型用法代码示例。如果您正苦于以下问题:C# GamePadState类的具体用法?C# GamePadState怎么用?C# GamePadState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GamePadState类属于Microsoft.Xna.Framework.Input命名空间,在下文中一共展示了GamePadState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
public override void Update(GameTime gameTime, GamePadState newGamePadState, GamePadState oldGamePadState, KeyboardState newKeyboardState, KeyboardState oldKeyboardState)
{
if ((newGamePadState.Buttons.A != oldGamePadState.Buttons.A && newGamePadState.Buttons.A == ButtonState.Pressed)
|| (newKeyboardState.IsKeyDown(Keys.Enter) && oldKeyboardState.IsKeyUp(Keys.Enter))) {
Game.GameStartingScreen = GameStartingScreen.SetupScreen;
}
}
示例2: GetInput
public static List<InputManager.ACTIONS> GetInput()
{
currentGamePadState = GamePad.GetState(PlayerIndex.One);
List<InputManager.ACTIONS> actions = new List<InputManager.ACTIONS>();
if (currentGamePadState.IsButtonUp(Buttons.A) && previousGamePadState.IsButtonDown(Buttons.A))
{
actions.Add(InputManager.ACTIONS.JUMP);
}
if (currentGamePadState.ThumbSticks.Left.X > 0 || currentGamePadState.DPad.Right == ButtonState.Pressed)
{
actions.Add(InputManager.ACTIONS.RIGHT);
}
else if (currentGamePadState.ThumbSticks.Left.X < 0 || currentGamePadState.DPad.Left == ButtonState.Pressed)
{
actions.Add(InputManager.ACTIONS.LEFT);
}
if (currentGamePadState.IsButtonUp(Buttons.Y) && previousGamePadState.IsButtonDown(Buttons.Y))
{
actions.Add(InputManager.ACTIONS.TOGGLE);
}
previousGamePadState = currentGamePadState;
return actions;
}
示例3: Update
public override void Update(GameTime gameTime, EventManager events)
{
base.Update(gameTime, events);
#region GamePad
// GamePad
P1LastGamePadState = P1GamePadState;
P1GamePadState = GamePad.GetState(PlayerIndex.One);
bool left = P1GamePadState.ThumbSticks.Left.X < 0.0f;
bool right = P1GamePadState.ThumbSticks.Left.X > 0.0f;
bool jump = (P1GamePadState.Buttons.A == ButtonState.Pressed
&& P1LastGamePadState.Buttons.A == ButtonState.Released);
bool action = (P1GamePadState.Buttons.B == ButtonState.Released
&& P1LastGamePadState.Buttons.B == ButtonState.Pressed);
#endregion
#region Keyboard
bool keyJump = (keyboard.IsKeyDown(Keys.Up)
&& lastKeyboard.IsKeyUp(Keys.Up));
bool keyDownLeft = keyboard.IsKeyDown(Keys.Left);
bool keyDownRight = keyboard.IsKeyDown(Keys.Right);
bool keyAction = keyboard.IsKeyUp(Keys.Space)
&& lastKeyboard.IsKeyDown(Keys.Space);
#endregion
if (action || keyAction) events.Notify(Event.Action, null);
}
示例4: InputHelper
/// <summary>
/// Constructs a new input state.
/// </summary>
public InputHelper(ScreenManager manager)
{
_currentKeyboardState = new KeyboardState();
_currentGamePadState = new GamePadState();
_currentMouseState = new MouseState();
_currentVirtualState = new GamePadState();
_lastKeyboardState = new KeyboardState();
_lastGamePadState = new GamePadState();
_lastMouseState = new MouseState();
_lastVirtualState = new GamePadState();
_manager = manager;
_cursorIsVisible = false;
_cursorMoved = false;
#if WINDOWS_PHONE
_cursorIsValid = false;
#else
_cursorIsValid = true;
#endif
_cursor = Vector2.Zero;
_handleVirtualStick = true;
}
示例5: Update
/// <summary>
/// Performs the logic to control the Player.
/// </summary>
/// <param name="pad">The state of the gamepad used to control this player.</param>
public void Update(GamePadState pad)
{
if (pad.ThumbSticks.Left.X >= 0.5) pos.X += speed;
if (pad.ThumbSticks.Left.X <= -0.5) pos.X -= speed;
if (pad.ThumbSticks.Left.Y >= 0.5) pos.Y -= speed;
if (pad.ThumbSticks.Left.Y <= -0.5) pos.Y += speed;
}
示例6: getAxis
public float getAxis(GamePadState gamePadState, bool left, bool x)
{
if (x)
{
if (left)
{
return gamePadState.ThumbSticks.Left.X;
}
else
{
return gamePadState.ThumbSticks.Right.X;
}
}
else
{
if (left)
{
return gamePadState.ThumbSticks.Left.Y;
}
else
{
return gamePadState.ThumbSticks.Right.Y;
}
}
}
示例7: FromInput
/// <summary>
/// Gets the current direction from a game pad and keyboard.
/// </summary>
public static Buttons FromInput(GamePadState gamePad, KeyboardState keyboard)
{
Buttons direction = None;
// Get vertical direction.
if (gamePad.IsButtonDown(Buttons.DPadUp) ||
gamePad.IsButtonDown(Buttons.LeftThumbstickUp) ||
keyboard.IsKeyDown(Keys.Up))
{
direction |= Up;
}
else if (gamePad.IsButtonDown(Buttons.DPadDown) ||
gamePad.IsButtonDown(Buttons.LeftThumbstickDown) ||
keyboard.IsKeyDown(Keys.Down))
{
direction |= Down;
}
// Comebine with horizontal direction.
if (gamePad.IsButtonDown(Buttons.DPadLeft) ||
gamePad.IsButtonDown(Buttons.LeftThumbstickLeft) ||
keyboard.IsKeyDown(Keys.Left))
{
direction |= Left;
}
else if (gamePad.IsButtonDown(Buttons.DPadRight) ||
gamePad.IsButtonDown(Buttons.LeftThumbstickRight) ||
keyboard.IsKeyDown(Keys.Right))
{
direction |= Right;
}
return direction;
}
示例8: GamePadController
public virtual void GamePadController(GamePadState state)
{
if (state.DPad.Down == ButtonState.Pressed && !(_previousGamePadState.DPad.Down == ButtonState.Pressed))
{
_selectedIndex++;
if (_selectedIndex == _levels.Length)
_selectedIndex--;
}
else if (state.DPad.Up == ButtonState.Pressed && !(_previousGamePadState.DPad.Up == ButtonState.Pressed))
{
_selectedIndex--;
if (_selectedIndex < 0)
_selectedIndex++;
}
else if (state.Buttons.A == ButtonState.Pressed &&!(_previousGamePadState.Buttons.A ==ButtonState.Pressed))
{
var sample = _levels[_selectedIndex].CreateLevelFunction();
sample.OnLoad();
CurrentLevel = sample;
}
_previousGamePadState = state;
}
示例9: Initialize
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
previousGamePadState = GamePad.GetState(PlayerIndex.One);
}
示例10: Update
//Methods
//Update & Draw
public void Update(MouseState mouse, KeyboardState keyboard, GamePadState gamePadState)
{
if (keyboard.IsKeyUp(Keys.Escape) && gamePadState.Buttons.Start == ButtonState.Released)
pauseAllowed = true;
if ((keyboard.IsKeyDown(Keys.Escape) || gamePadState.Buttons.Start == ButtonState.Pressed) && pauseAllowed)
{
pauseAllowed = false;
Game1.gameState = GameState.Pause;
}
if (mouse.X > 800)
{
Map.Current.position.X++;
player.position.X++;
}
if (mouse.X < 200)
{
Map.Current.position.X--;
player.position.X--;
}
Map.Current.Update();
player.Update(mouse, keyboard, gamePadState);
}
示例11: InputManager
//********************************************
// Constructors
//********************************************
public InputManager(Main game)
{
z_game = game;
z_prevKeyState = z_curKeyState = new KeyboardState();
z_prevPadState = z_curPadState = new GamePadState();
SetDefaultControls();
}
示例12: HandleInput
/// <summary>
/// Exit the screen after a tap or click
/// </summary>
/// <param name="input"></param>
private void HandleInput(MouseState mouseState, GamePadState padState)
{
if (!isExit)
{
#if WINDOWS_PHONE
if (ScreenManager.input.Gestures.Count > 0 &&
ScreenManager.input.Gestures[0].GestureType == GestureType.Tap)
{
isExit = true;
}
#else
PlayerIndex result;
if (mouseState.LeftButton == ButtonState.Pressed)
{
isExit = true;
}
else if (ScreenManager.input.IsNewButtonPress(Buttons.A, null, out result) ||
ScreenManager.input.IsNewButtonPress(Buttons.Start, null, out result))
{
isExit = true;
}
#endif
}
}
示例13: CheckHorizontalMovementKeys
//
// Horizontal Movement
protected void CheckHorizontalMovementKeys(KeyboardState ksKeys,
GamePadState gsPad)
{
bool bResetTimer = false;
player.Thrusting = false;
if ((ksKeys.IsKeyDown(Keys.Right)) || (gsPad.ThumbSticks.Left.X > 0))
{
if (player.ScrollRate < iMaxHorizontalSpeed)
{
player.ScrollRate += player.AccelerationRate;
if (player.ScrollRate > iMaxHorizontalSpeed)
player.ScrollRate = iMaxHorizontalSpeed;
bResetTimer = true;
}
player.Thrusting = true;
player.Facing = 0;
}
if ((ksKeys.IsKeyDown(Keys.Left)) || (gsPad.ThumbSticks.Left.X < 0))
{
if (player.ScrollRate > -iMaxHorizontalSpeed)
{
player.ScrollRate -= player.AccelerationRate;
if (player.ScrollRate < -iMaxHorizontalSpeed)
player.ScrollRate = -iMaxHorizontalSpeed;
bResetTimer = true;
}
player.Thrusting = true;
player.Facing = 1;
}
if (bResetTimer)
player.SpeedChangeCount = 0.0f;
}
示例14: ProcessController
public void ProcessController()
{
keyState = Keyboard.GetState();
padState = GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One);
Actor hero = (Actor)game.Hero;
/*
* GamePad inputs
*/
//Moving
if (padState.IsButtonDown(Buttons.LeftThumbstickLeft) || keyState.IsKeyDown(Keys.Left))
{
hero.Pos.X -= 1.5f;
hero.NextPosture(ActorDirection.Left);
}
if (padState.IsButtonDown(Buttons.LeftThumbstickRight) || keyState.IsKeyDown(Keys.Right))
{
hero.Pos.X += 1.5f;
hero.NextPosture(ActorDirection.Right);
}
//Jump
if (padState.IsButtonDown(Buttons.LeftThumbstickUp))
{
}
if (padState.IsButtonDown(Buttons.LeftThumbstickDown))
{
}
}
示例15: Update
public override void Update(float deltaTime)
{
if (id == World.gameId)
{
gamePad = GamePad.GetState(PlayerIndex.One);
keyboard = Keyboard.GetState();
if (gamePad.Buttons.Y == ButtonState.Pressed &&
oldGamePad.Buttons.Y == ButtonState.Released &&
World.inMenu == false ||
keyboard.IsKeyDown(Keys.Tab) &&
oldKeyboard.IsKeyUp(Keys.Tab) &&
World.inMenu == false)
{
World.inMenu = true;
World.menuManager.SwitchMenu(World.menuManager.shop);
}
else if (keyboard.IsKeyDown(Keys.Tab) &&
oldKeyboard.IsKeyUp(Keys.Tab) &&
World.inMenu == true)
{
World.menuManager.CurrentMenu.BackOut();
}
}
oldGamePad = gamePad;
oldKeyboard = keyboard;
base.Update(deltaTime);
}