Accelerometer or Touch in Farseer for WP7 XNA

Topics: Developer Forum
Apr 27, 2011 at 8:15 PM

Any samples using accelerometer on WP7 XNA game with farseer?

Also In my game in one of the screen I want to only enable Flick or Drag gesture. How can I do it.

I am using HandleInput(InputHelper Input), which by default enables all touch gestures. Besides I also want to distinguish flick among horizontal or vertical.

Tried through TouchPanel by enabling the required gestures during initialization. But couldn't enter while loop.

public override void HandleInput(InputHelper input)
{
       while (TouchPanel.IsGestureAvailable)
       {
                GestureSample _gesture = TouchPanel.ReadGesture();

                if (_gesture.GestureType == GestureType.Flick)
                {
                    if (_gesture.Delta.X >= 15 && _gesture.Delta.Y <= 15)
                    {
                        _ballBody.LinearVelocity += new Vector2(_gesture.Delta.X, 0);
                        
                    }

                    else if (_gesture.Delta.X <= 15 && _gesture.Delta.Y >= 15)
                    {
                        _ballBody.LinearVelocity += new Vector2(0, _gesture.Delta.Y);
                        
                    }
                }
        }
        base.HandleInput(input);
}

Am I missing anything, or is there any workaround?

Thanks

Pavan

 

Apr 27, 2011 at 9:40 PM

If you just want to enable certain gestures in your Initialize method TouchPanel.EnabledGestures = GestureType.Flick | GestureType.FreeDrag; .  And in your update


            if (TouchPanel.IsGestureAvailable)
            {
                GestureSample gesture = TouchPanel.ReadGesture();
                switch (gesture.GestureType)
                {
                    case GestureType.Flick:
                       //Do Something
                        break;


                    case GestureType.FreeDrag:
                       //Do Something
                        break;               

                   }
            }

Hope this helps

Apr 28, 2011 at 7:39 AM

I guess you missed my point. I had tried the above method but after putting breakpoints. I found that I couldn't enter the while loop in my example and if loop in your example