public static Vector2 GetThumbstick(this GamePadState gamePad, GamePadThumbStick stick) { switch (stick) { case GamePadThumbStick.Left: return(new Vector2(gamePad.ThumbSticks.Left.X, gamePad.ThumbSticks.Left.Y)); case GamePadThumbStick.Right: return(new Vector2(gamePad.ThumbSticks.Right.X, gamePad.ThumbSticks.Right.Y)); default: return(Vector2.zero); } }
/// <summary> /// Constructs an InputAction which tracks GamePad thumb sticks. /// </summary> /// <param name="playerIndex">The index of the player using this input.</param> /// <param name="buttonAction">What state the button should be in to activate.</param> /// <param name="thumbStick">Which thumb stick to track.</param> /// <param name="thumbStickAxis">The axis of movement to be tracked.</param> /// <param name="deadZoneType">The type of dead zone.</param> /// <param name="deadZoneMin">The minimum Degree which will not be sensed.</param> /// <param name="deadZoneMax">The maximum Degree which will not be sensed.</param> public GamePadThumbStickInputAction( PlayerIndex playerIndex, ButtonAction buttonAction, GamePadThumbStick thumbStick, GamePadThumbStickAxis thumbStickAxis, GamePadDeadZone deadZoneType, float deadZoneMin, float deadZoneMax) : base(playerIndex, buttonAction) { mGamePadThumbStick = thumbStick; mGamePadThumbStickAxis = thumbStickAxis; mGamePadDeadZone = deadZoneType; mDeadZoneMax = deadZoneMax; mDeadZoneMin = deadZoneMin; }
/// <summary> /// Creates a new GamePadThumbStickBinding instance for the specified player's gamepad, bound to the specified thumbstick, and with the provided X- and Y-axis threshold values. /// </summary> /// <param name="player">Player whose gamepad will be bound.</param> /// <param name="thumbstick">Thumbstick to bind.</param> /// <param name="xMinimumThreshold">Minimum X-axis value that will match.</param> /// <param name="xMaximumThreshold">Maximum X-axis value that will match.</param> /// <param name="yMinimumThreshold">Minimum Y-axis value that will match.</param> /// <param name="yMaximumThreshold">Maximum Y-axis value that will match.</param> /// <remarks>X-axis values must be from -1.0 .. 1.0, inclusive, where negative values are to the left and positive values to the right. Y-axis values must also be from -1.0 .. 1.0, /// where negative values are down and positive values up.</remarks> /// <exception cref="System.ArgumentOutOfRangeException">Thrown if xMinimumThreshold is greater than xMaximumThreshold, or if yMinimumThreshold is greater than yMaximumThreshold.</exception> public GamePadThumbStickMatcher(PlayerIndex player, GamePadThumbStick thumbstick, float xMinimumThreshold, float xMaximumThreshold, float yMinimumThreshold, float yMaximumThreshold) : base(player) { if (xMinimumThreshold > xMaximumThreshold) { throw new ArgumentOutOfRangeException("xMinimumThreshold"); } if (yMinimumThreshold > yMaximumThreshold) { throw new ArgumentOutOfRangeException("yMinimumThreshold"); } ThumbStick = thumbstick; XMinimumThreshold = xMinimumThreshold; XMaximumThreshold = xMaximumThreshold; YMinimumThreshold = yMinimumThreshold; YMaximumThreshold = yMaximumThreshold; }
/// <summary> /// Gets a thumbstick sprite frame from "Sprites\UI\controller.png" /// </summary> /// <param name="thumbstick">The thumbstick mapped to the sprite.</param> public static Sprite GetIcon(GamePadThumbStick thumbstick) { int iconPath; switch (thumbstick) { case GamePadThumbStick.Right: iconPath = 61; break; case GamePadThumbStick.Left: iconPath = 60; break; default: throw new ArgumentOutOfRangeException("thumbstick", thumbstick, null); } return(Resources.LoadAll <Sprite>(GamePadIconHelper.ControllerSpritePath)[iconPath]); }
/// <summary> /// Release thumbstick stored in the polling handler. This occurs whenever a thumbstick /// is literally released by a player. /// </summary> /// <param name="thumbstick"><see cref="GamePadThumbStick"/> to release, holds stick type and player index</param> private void ReleaseThumbstick(GamePadThumbStick thumbstick) { this.thumbsticks[(int)thumbstick.Player, (int)thumbstick.StickType] = Vector2.Zero; }