public InputAction(ThumbStick myThumbStick, ThumbStickDirection myDirection, int myPlayerIndex, bool myNewPressOnly) { thumbStick = myThumbStick; direction = myDirection; playerIndex = myPlayerIndex; newStickPressOnly = myNewPressOnly; inputType = InputType.thumbstick; }
/// <summary> /// Returns a core assigned description of the specified thumbstick, if any is assigned. /// </summary> /// <param name="port">The port of the analog joypad.</param> /// <param name="thumbstick">The thumbstick to query.</param> /// <param name="direction">The direction to query.</param> /// <returns>If a description is assigned, the description, otherwise "".</returns> public string GetAnalogJoypadDescription(int port, ThumbStick thumbstick, ThumbStickDirection direction) { string desc = ""; inputDescriptors.TryGetValue(DeviceType.Joypad + "," + port + "," + ((int)thumbstick) + "," + ((int)direction), out desc); return desc; }
/// <summary> /// Allows the game component to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime) { _lastKeyboardState = _keyboardState; _keyboardState = Keyboard.GetState(); _lastGamePadStates = (GamePadState[])_gamePadStates.Clone(); foreach (PlayerIndex index in Enum.GetValues(typeof(PlayerIndex))) _gamePadStates[(int)index] = GamePad.GetState(index); // Set thumbstick directions Vector2 thumbStickLeftVector = _gamePadStates[(int) PlayerIndex.One].ThumbSticks.Left; if (thumbStickLeftVector.Y < -ThumbStickSensitivity) ThumbStickLeft = ThumbStickDirection.Down; else if (thumbStickLeftVector.Y > ThumbStickSensitivity) ThumbStickLeft = ThumbStickDirection.Up; else if (thumbStickLeftVector.X > ThumbStickSensitivity) ThumbStickLeft = ThumbStickDirection.Right; else if (thumbStickLeftVector.X < -ThumbStickSensitivity) ThumbStickLeft = ThumbStickDirection.Left; else ThumbStickLeft = ThumbStickDirection.Center; // DEBUG //Console.Clear(); //Console.WriteLine(ThumbStickLeft + " " + thumbStickLeftVector.X + ", " + thumbStickLeftVector.Y); base.Update(gameTime); }
public static bool IsThumbStickNewlyMoved(ThumbStick myThumbStick, ThumbStickDirection myDirection, int myPlayer) { if (newGamePads[myPlayer].IsConnected) { if (myThumbStick == ThumbStick.Left) { switch (myDirection) { case ThumbStickDirection.up: if (newGamePads[myPlayer].ThumbSticks.Left.Y > deadZone && oldGamePads[myPlayer].ThumbSticks.Left.Y < deadZone) { return true; } break; case ThumbStickDirection.down: if (newGamePads[myPlayer].ThumbSticks.Left.Y < -deadZone && oldGamePads[myPlayer].ThumbSticks.Left.Y > -deadZone) { return true; } break; case ThumbStickDirection.left: if (newGamePads[myPlayer].ThumbSticks.Left.X < -deadZone && oldGamePads[myPlayer].ThumbSticks.Left.X > -deadZone) { return true; } break; case ThumbStickDirection.right: if (newGamePads[myPlayer].ThumbSticks.Left.X > deadZone && oldGamePads[myPlayer].ThumbSticks.Left.X < deadZone) { return true; } break; } } if (myThumbStick == ThumbStick.Right) { switch (myDirection) { case ThumbStickDirection.up: if (newGamePads[myPlayer].ThumbSticks.Right.Y > deadZone && oldGamePads[myPlayer].ThumbSticks.Right.Y < deadZone) { return true; } break; case ThumbStickDirection.down: if (newGamePads[myPlayer].ThumbSticks.Right.Y < -deadZone && oldGamePads[myPlayer].ThumbSticks.Right.Y > -deadZone) { return true; } break; case ThumbStickDirection.left: if (newGamePads[myPlayer].ThumbSticks.Right.X < -deadZone && oldGamePads[myPlayer].ThumbSticks.Right.X > -deadZone) { return true; } break; case ThumbStickDirection.right: if (newGamePads[myPlayer].ThumbSticks.Right.X > deadZone && oldGamePads[myPlayer].ThumbSticks.Right.X < deadZone) { return true; } break; } } } return false; }