Looking at the new samples on the creators.xna.com I see they have an example for using virtual thumb sticks in a Windows Phone 7 game. I like it, but I decided I wanted a version with the thumbs sticks fixed in place, much like you'd see in an iPhone shooter like Call of Duty: World at War: Zombies. Here's a screen of the result.
The first thing I decided was to not make the Virtual Thumbstick class static, but instead a DrawableGameComponet. While not consistent with other XNA input implementations, it allows you to add one or more thumbsticks to the list of components and let them load, draw and update without calling any methods. You can simply look at the thumbstick position, see if it's greater than zero, and determine what to do with it when it is.
I also added support for Independent Axis and Circular dead zones, where the position will always be zero when falling in the dead zone. They're needed on real gamepads since analog controls never truly return to zero at rest, but I felt not having these may make the virtual sticks feel too sensitive. I don't have a device to test on so it's up in the air if this will prove useful or not. The zone percentage can be set to zero if you don't want this feature. For more on dead zones check out Shawn Hargreaves blog post about it here.
Instead of me stepping through the code, download the zip and take a look. The original sample was commented well and I tried to do the same. Since it's based on the XNA sample and that is released with the Microsoft Permissive License, this is also released under that license. You'll find a copy with the source. Basically, use it for what ever you want, provided as-is, don't sue please, yada, yada. Let me know if you find it useful or have any improvements, ideas, etc...
fixedvirtualthumbstick.zip |