本文整理汇总了C#中Microsoft.Xna.Framework.Input.GamePadState.IsButtonDown方法的典型用法代码示例。如果您正苦于以下问题:C# GamePadState.IsButtonDown方法的具体用法?C# GamePadState.IsButtonDown怎么用?C# GamePadState.IsButtonDown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Input.GamePadState
的用法示例。
在下文中一共展示了GamePadState.IsButtonDown方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
public void Update(GamePadState pad)
{
if (pad.IsButtonDown(Buttons.LeftThumbstickDown) && !oldPad.IsButtonDown(Buttons.LeftThumbstickDown))
{
if (current < 3)
{
current++;
}
}
if (pad.IsButtonDown(Buttons.LeftThumbstickUp) && !oldPad.IsButtonDown(Buttons.LeftThumbstickUp))
{
if (current > 1)
{
current--;
}
}
if (pad.IsButtonDown(Buttons.A) && oldPad.IsButtonUp(Buttons.A))
{
if (current == 1)
{
FirstGame.start = true;
}
else if (current == 3)
{
FirstGame.exit = true;
}
}
oldPad = pad;
}
示例2: AttackAdd
// Adds an attack when the attack button is pressed accompanied by sound and animation
public static void AttackAdd(ContentManager Content, Player ninja, List<PlayerAttack> ninjaAttacks,
KeyboardState presentKey, KeyboardState pastKey,
GamePadState pressentButton, GamePadState pastButton)
{
if (presentKey.IsKeyDown(Keys.Space) && pastKey.IsKeyUp(Keys.Space)
|| pressentButton.IsButtonDown(Buttons.A) && pastButton.IsButtonUp(Buttons.A))
{
// if the attack button is pressed a new attack will be added to the list
ninjaAttacks.Add(new PlayerAttack(Content.Load<Texture2D>("Images\\Attack"),
new Vector2(ninja.PositionX + (int)(ninja.Texture.Width * 0.8),
ninja.PositionY + (int)(ninja.Texture.Height / 2.25))));
// A sound effect will be played each time we press the attack button
ninja.PlaySound();
}
// The animation texture of the character will change with each attack
if (presentKey.IsKeyDown(Keys.Space) || pressentButton.IsButtonDown(Buttons.A))
{
ninja.Texture = Content.Load<Texture2D>("Images\\NinjaFrame1-2");
}
else
{
ninja.Texture = Content.Load<Texture2D>("Images\\NinjaFrame1-1");
}
}
示例3: Update
public void Update()
{
gamePadState = GamePad.GetState(PlayerIndex.One);
bool foundInput = false;
if (gamePadState.IsButtonDown(Buttons.Start) && !startPressed)
{
startPressed = true;
new StartButtonCommand().Execute();
}
else if (gamePadState.IsButtonUp(Buttons.Start) && startPressed)
{
startPressed = false;
}
if (playableObject.IsEnteringPipe || playableObject.IsExitingPipe)
{
new MarioNoInputCommand(playableObject).Execute();
}
else
{
if (gamePadState.IsButtonDown(Buttons.A) && !jumpPressed)
{
jumpPressed = true;
new MarioJumpCommand(playableObject).Execute();
foundInput = true;
}
else if (gamePadState.IsButtonDown(Buttons.A))
{
foundInput = true;
}
else if (gamePadState.IsButtonUp(Buttons.A) && jumpPressed)
{
jumpPressed = false;
}
if (gamePadState.IsButtonDown(Buttons.B))
{
playableObject.MaxHorizontalVelocity = GameValues.MarioRunningSpeed;
new MarioRunCommand(playableObject).Execute();
}
else
{
playableObject.MaxHorizontalVelocity = GameValues.MarioWalkingSpeed;
}
foreach (KeyValuePair<Buttons, ICommand> item in buttonMap)
{
if (gamePadState.IsButtonDown(item.Key))
{
item.Value.Execute();
foundInput = true;
}
}
if (!foundInput)
{
new MarioNoInputCommand(playableObject).Execute();
}
}
}
示例4: updateSingleplayer
public static void updateSingleplayer()
{
prevGamepad = currGamepad;
currGamepad = GamePad.GetState(PlayerIndex.One);
Vector2 moveVec = new Vector2(0, 0);
if (currGamepad.IsButtonDown(Buttons.DPadUp)) moveVec += new Vector2(0, -speed);
if (currGamepad.IsButtonDown(Buttons.DPadLeft)) moveVec += new Vector2(-speed, 0);
if (currGamepad.IsButtonDown(Buttons.DPadDown)) moveVec += new Vector2(0, speed);
if (currGamepad.IsButtonDown(Buttons.DPadRight)) moveVec += new Vector2(speed, 0);
if (isClicked(Buttons.A) && !isJumping) isJumping = true;
if (isJumping && !limitReached)
{
moveVec += new Vector2(0, -speed);
test += speed;
if (test == limit)
limitReached = true;
}
else if (limitReached)
{
moveVec -= new Vector2(0, -speed);
test -= speed;
if (test == 0)
{
limitReached = false;
isJumping = false;
}
}
Camera2D.movePosition(moveVec);
}
示例5: 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))
{
}
}
示例6: FireCannons
public static void FireCannons(GamePadState gs, GamePadState previousGamePadState, Player player, GameTime gameTime)
{
if (gs.IsButtonDown(actionKeys[Action.FireLeftCannon]))
{
player.FireLeftCannons(gameTime);
}
if (gs.IsButtonDown(actionKeys[Action.FireRightCannon]))
{
player.FireRightCannons(gameTime);
}
}
示例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: GetState
/// <summary>
/// Generates a GamePadState based on the touch input provided (as applied to the on screen controls) and the gamepad state
/// </summary>
public GamePadState GetState(TouchCollection touchState, GamePadState gpState)
{
//Work out what buttons are pressed based on the touchState
Buttons buttonsPressed = 0;
foreach (TouchLocation touch in touchState)
{
if (touch.State == TouchLocationState.Moved || touch.State == TouchLocationState.Pressed)
{
//Scale the touch position to be in _baseScreenSize coordinates
Vector2 pos = touch.Position;
Vector2.Transform(ref pos, ref globalTransformation, out pos);
if (pos.X < 128)
buttonsPressed |= Buttons.DPadLeft;
else if (pos.X < 256)
buttonsPressed |= Buttons.DPadRight;
else if (pos.X >= baseScreenSize.X - 128)
buttonsPressed |= Buttons.A;
}
}
//Combine the buttons of the real gamepad
GamePadButtons gpButtons = gpState.Buttons;
buttonsPressed |= (gpButtons.A == ButtonState.Pressed ? Buttons.A : 0);
buttonsPressed |= (gpButtons.B == ButtonState.Pressed ? Buttons.B : 0);
buttonsPressed |= (gpButtons.X == ButtonState.Pressed ? Buttons.X : 0);
buttonsPressed |= (gpButtons.Y == ButtonState.Pressed ? Buttons.Y : 0);
buttonsPressed |= (gpButtons.Start == ButtonState.Pressed ? Buttons.Start : 0);
buttonsPressed |= (gpButtons.Back == ButtonState.Pressed ? Buttons.Back : 0);
buttonsPressed |= gpState.IsButtonDown(Buttons.DPadDown) ? Buttons.DPadDown : 0;
buttonsPressed |= gpState.IsButtonDown(Buttons.DPadLeft) ? Buttons.DPadLeft : 0;
buttonsPressed |= gpState.IsButtonDown(Buttons.DPadRight) ? Buttons.DPadRight : 0;
buttonsPressed |= gpState.IsButtonDown(Buttons.DPadUp) ? Buttons.DPadUp : 0;
buttonsPressed |= (gpButtons.BigButton == ButtonState.Pressed ? Buttons.BigButton : 0);
buttonsPressed |= (gpButtons.LeftShoulder == ButtonState.Pressed ? Buttons.LeftShoulder : 0);
buttonsPressed |= (gpButtons.RightShoulder == ButtonState.Pressed ? Buttons.RightShoulder : 0);
buttonsPressed |= (gpButtons.LeftStick == ButtonState.Pressed ? Buttons.LeftStick : 0);
buttonsPressed |= (gpButtons.RightStick == ButtonState.Pressed ? Buttons.RightStick : 0);
var buttons = new GamePadButtons(buttonsPressed);
return new GamePadState(gpState.ThumbSticks, gpState.Triggers, buttons, gpState.DPad);
}
示例9: Update
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
_keyState = Keyboard.GetState();
_padState = GamePad.GetState(PlayerIndex.One);
//Let the Scene Manager do it's thing
if ((_prevKeyState.IsKeyDown(Keys.P) && !_keyState.IsKeyDown(Keys.P)) || (_prevPadState.IsButtonDown(Buttons.Y) && !_padState.IsButtonDown(Buttons.Y)))
{
// The 'P' key has just been released
// This will only fire ONCE when the 'P' key is released
if (_pauseOn)
_pauseOn = false;
else
_pauseOn = true;
}
if(!_pauseOn)
_manager.NextScene().Update(gameTime);
//Console.WriteLine();
_prevKeyState = _keyState;
_prevPadState = _padState;
base.Update(gameTime);
}
示例10: CheckInput
/// <summary>
/// Call this method when input is received to have the console react to the user's commands.
/// </summary>
/// <param name="kbs">The current keyboard state.</param>
/// <returns>The Command that corresponds to the user's input.</returns>
public void CheckInput(GamePadState gs)
{
if (_menuActive)
{
if (gs.IsButtonDown(Buttons.Y) && _oldPad.IsButtonUp(Buttons.Y))
_menuActive = false;
}
else
{
// Should we bring the menu up?
if (gs.IsButtonDown(Buttons.Y) && _oldPad.IsButtonUp(Buttons.Y))
_menuActive = true;
}
_oldPad = gs;
}
示例11: Update
public override void Update( TimeSpan gameTime, KeyboardState keyState, MouseState mouseState, GamePadState padState )
{
if ( keyState.IsKeyDown( Keys.Space ) || padState.IsButtonDown( Buttons.X ) || keyState.IsKeyDown( Keys.X ) )
{
ReferMenu( null );
}
}
示例12: handleController
private List<Command> handleController()
{
List<Command> commands = new List<Command>();
padState = GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One);
Vector2 move = new Vector2();
move.X = 0;
move.Y = 0;
if (padState.ThumbSticks.Left.Length() > .7f)
{
move.X = padState.ThumbSticks.Left.X * .7f;
move.Y = -padState.ThumbSticks.Left.Y * .7f;
}
commands.Add(new MoveCommand(move));
Vector2 gazeDir = new Vector2();
gazeDir.X = padState.ThumbSticks.Right.X;
gazeDir.Y = -padState.ThumbSticks.Right.Y;
commands.Add(new GazeCommand(gazeDir));
if (padState.IsButtonDown(Buttons.RightShoulder))
commands.Add(new PunchCommand());
return commands;
}
示例13: InputsPlayer
public void InputsPlayer(GameTime gameTime, bool move, bool jump, Player player)
{
// Save previous keyboard/gamepad states
previousKeyboardState = currentKeyboardState;
previousGamepadState = currentGamepadState;
// Read current keyboard/gamepad
currentKeyboardState = Keyboard.GetState();
currentGamepadState = GamePad.GetState(PlayerIndex.One);
if (move && player.CanMove)
{
if (currentKeyboardState.IsKeyDown(Keys.Left) || currentGamepadState.ThumbSticks.Left.X < 0)
player.Move(-1f);
else if (currentKeyboardState.IsKeyDown(Keys.Right) || currentGamepadState.ThumbSticks.Left.X > 0)
player.Move(1f);
else
player.Move(0f);
}
if (player.CanJump && jump)
{
if (currentGamepadState.IsButtonDown(Buttons.A) && previousGamepadState.IsButtonUp(Buttons.A))
player.Jump();
else if (currentKeyboardState.IsKeyDown(Keys.Z) && previousKeyboardState.IsKeyUp(Keys.Z))
player.Jump();
}
if (player.IsOverDoor)
{
if (currentGamepadState.ThumbSticks.Left.Y < 0
&& previousGamepadState.ThumbSticks.Left.Y < 0
&& player.Velocity.X == 0
)
player.EnterDoor();
else if (currentKeyboardState.IsKeyDown(Keys.Up)
&& previousKeyboardState.IsKeyUp(Keys.Up)
&& player.Velocity.X == 0
)
player.EnterDoor();
}
if (currentGamepadState.IsButtonDown(Buttons.B) && previousGamepadState.IsButtonUp(Buttons.B))
player.Attack(gameTime);
else if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))
player.Attack(gameTime);
}
示例14: PickupGold
public static void PickupGold(GamePadState gs, GamePadState previousGamePadState, Player player, GameTime gameTime)
{
var pickupGoldButton = actionKeys[Action.PickupGold];
if (gs.IsButtonDown(pickupGoldButton) && previousGamePadState.IsButtonUp(pickupGoldButton))
{
player.AttemptPickupGold();
}
}
示例15: Update
public void Update()
{
motion = Vector2.Zero;
keyboardState = Keyboard.GetState();
gamePadState = GamePad.GetState(PlayerIndex.One);
if (keyboardState.IsKeyDown(Keys.Left) || gamePadState.IsButtonDown(Buttons.LeftThumbstickLeft))
motion.X = -1;
if (keyboardState.IsKeyDown(Keys.Right) || gamePadState.IsButtonDown(Buttons.LeftThumbstickRight))
motion.X = 1;
motion.X *= paddleSpeed;
position += motion;
checkInBounds();
}