Partilhar via


Microsoft XNA 4.0 beta: the Touch Gesture

Hi all,

As you have probably seen XNA 4.0 beta has been published this Monday along with the windows Phone Development Tools Beta. Even if this version doesn’t support Xbox 360 title for the moment, it’s interesting to take a closer look at the big picture to get prepared for the future (which will of course support Xbox 360 games J ).This new version provides some bugs fixes, but some improvements as well, and I want precisely to talk of one of them.

The new that I found really the most interesting was the introduction of a touch gesture system in XNA Framework, this allows you to simply program your touch interaction using the API’s functions and not to have you reimplement all the gesture handling personally . For example, keyword “Tap” represent a brief interaction of touching the screen, “hold” is a long touching of the screen,… This new feature is simpler than before: you just have to activate the gestures trough a Bitflag, and then you can freely use them!

TouchPanel.EnabledGestures = GestureType.Tap | GestureType.DoubleTap |GestureType.FreeDrag;

The EnabledGestures is the bit Mask to activate the gestures and the | are simply bitwise addition (10|01 =11), so this will simply enables you to use the “Tap”, “DoubleTap” and “FreeDrag” functions. It’s recommended to activate only the function that you will use for performance concerns. Then you can simply “read” the used gesture with the function TouchPanel.ReadGesture(); which will return a <GestureSample> type. This type will permit you to know which Gesture was detected with the field “GestureType” but also to know where the Interaction Happened trough the <Vector2> Position, and the time when it happened trough <TimeSpan> TimeStamp!

There are of course more features that are interesting, I will surely talk about them in further blog post. If you want to go further with this new Gestures API, I warmly recommend this blog post from Nick Gravelyn on which I based this article https://blogs.msdn.com/b/nicgrave/archive/2010/07/12/touch-gestures-on-windows-phone-7.aspx. If you are new to game programming with XNA but interested in beginning, just check this page of tutorials which will slowly explain you all that you must know https://creators.xna.com/en-US/education/gettingstarted.

Kind Regards,

Mikhail, Lead Student Partner Geneva

Comments

  • Anonymous
    August 12, 2010
    nice post. bit mask is use for long in other system, but I don't know the specificity of that API. So I think it's a good thing to use that trick. ps: thanks to explain us what is the bitwise or... ;)