Substitute for arrow keys on WP7

Feb 15, 2011 at 2:00 PM

Hi all,

After have been given loads of help (I'm not a skilled programmer really), I now have a PH game for Windows Phone 7. I originally designed the game for Silverlight/PC and am using the arrow keys (via PhysicsKeyTriggers) to move my player object around.

I just realised that there are no arrow keys on WP7... :-)

I don't want the user to be able to drag the player object - the game would be too easy. I'm thinking of putting some arrow icons (rectangles with triggers) on the gameboard. However, I don't know what triggertype to use to get things to work. This is what I'd like: While rectArrowRight is pressed, ForceX 5 should be given to my player object.

Is this doable? If not, is there a more common way to do this?

Many thanks for any hints...


Feb 20, 2011 at 1:54 PM

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input.Touch;

TouchPanel.EnabledGestures = GestureType.Hold | GestureType.Flick | GestureType.Tap | GestureType.FreeDrag | GestureType.HorizontalDrag | GestureType.VerticalDrag | GestureType.DragComplete | GestureType.Pinch | GestureType.PinchComplete;

Then use ManipStarted, ManipDelta, and ManipCompleted like:




 private void ManipStarted(object sender, ManipulationStartedEventArgs e)
            // The IsGestureAvailable property will tell us if a gesture has been recognised. It's possible there's more than one            
            while (TouchPanel.IsGestureAvailable)
            {   // Read the current gesture
                GestureSample gesture = TouchPanel.ReadGesture();

                // Temporarily update page title to indicate type of gesture and its properties (for the purpose of the demo).                
                if (gesture.GestureType == GestureType.FreeDrag | gesture.GestureType == GestureType.HorizontalDrag | gesture.GestureType == GestureType.VerticalDrag)
                    textBlock1.Text = string.Format(gesture.GestureType.ToString() + " {0}, {1}", gesture.Position.X, gesture.Position.Y);
                    textBlock1.Text = string.Format(gesture.GestureType.ToString() + " {0}, {1}", gesture.Position.X, gesture.Position.Y);
Feb 28, 2011 at 9:41 AM


Thanks for the reply, but I was really asking for how to get to the next step, tha is, how to hook up to the physicskeytrigger event.

All ideas are welcome! :-)