AnalogStick
Introduction
The AnalogStick class provides a variety of information about an AnalogStick on an Xbox360GamePad.
Position
The Xbox360GamePad class exposes two analog sticks: LeftStick and RightStick. The following code will move a Sprite according to how the LeftStick is positioned: Add the following at class scope:
Add the following to Initialize after initializing FlatRedBall:
Add the following to Update:
As DPad
The analog stick can report information as if it were a DPad, which is useful for games where you control an object or UI over a discrete set of positions, such as moving a selection cursor over a grid of characters in a fighting game. The following code shows how to move a Sprite by 16 pixels in any direction:
AsDPadRepeatRate
The AsDPadRepeatRate method results in the AnalogStick behaving as a DPad with repeat-rate logic. In other words, when the user holds the AnalogStick initially pushes the analog stick in a direction, the AsDPadRepeatRate method returns true. It keeps track of the last time it returned true and will continue to return true at a set frequency so long as the user holds the AnalogStick in that direction. The following code creates a Sprite which is moved .5 units every time the analog stick is pressed or whenever the push triggers through the repeat-rate logic. Add the following at class scope:
Add the following to Initialize after initializing FlatRedBall:
Add the following to Update:
Repeat Rate Frequency
The amount of time between the initial push and the first repeat is longer than the space between subsequent repeats. This is similar to the repeat rate resulting from holding down a key on the keyboard.
[subpages depth="1"]
Last updated