Help understanding the TimerLoop

Aug 17, 2010 at 12:39 AM

I am still getting my feet wet with the helper. In previous projects, I was using a simple storyboard for my 'game loop'. Can anyone point me to some examples so I can start to udnerstand how the timer loop might be different?

The same logic I used to move things on a canvas in a game loop now do way too much with a timer loop (or that's my best explanation of what I think is happening).

I have an ellipse on a WP7 game, and I want to move a sprite based on where the ellipse is 'touched'

so, when a touch on the ellipse is detected, I create a vector based on it...

        void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            foreach (var touchPoint in e.GetTouchPoints(null))
            {
                //Debug.WriteLine(touchPoint.TouchDevice.DirectlyOver);
                if (touchPoint.TouchDevice.DirectlyOver != null)
                {

                    switch (touchPoint.TouchDevice.DirectlyOver.ToString())
                    {
                        case "System.Windows.Shapes.Ellipse":
                            if (touchPoint.Action == TouchAction.Up)
                            {
                                GamePadDirection = Vector2.Zero;
                            }
                            else
                            {
                                //GamePadDirection = MathHelper.CreateVectorFromAngle(MathHelper.AngleToPoint( touchPoint.Position, GamePadPosition), 100);

                                var radians = Math.Atan2(touchPoint.Position.Y - GamePadPosition.Y, touchPoint.Position.X - GamePadPosition.X);
                                var degrees = MathHelper2.RadiansToDegrees(radians);
                                GamePadDirection = MathHelper2.CreateVectorFromAngle(degrees + 90, .01); //on a timer loop, give the sprite this velocity
                            }
                            break;
                    }
                }
            }
        }

Next, on the timer loop, I apply that vetor to the Body of my sprite ( I also mess with friction to give it the feel I am looking for )...

        void _physicsController_TimerLoop(object source)
        {
            if (Player != null)
            {
                Vector2 force = Vector2.Zero;
                force.Y = -force.Y;
                if (GamePadDirection != Vector2.Zero)
                {
                    force += new Vector2(GamePadDirection.X, GamePadDirection.Y);

                    Player.BodyObject.LinearDragCoefficient = 0;
                }
                else
                {
                    Player.BodyObject.LinearDragCoefficient = 60;
                }
                Player.BodyObject.ApplyForce(force);        
            }
        }
When I run this, I get an issue that makes it look like the velocity is way too great:
http://twitpic.com/2fg9t9/full
I had all this working pretty well with Farseer, but have a radically different experience with the helper. 
In the first code snippet, I was originally using this and getting some decent movement:
                                GamePadDirection = MathHelper2.CreateVectorFromAngle(degrees + 90, 20000); //on a timer loop, give the sprite this velocity

 
Any ideas?
Thanks,
Coordinator
Aug 23, 2010 at 10:58 AM

Usually an overflow like this is because of some unrealistic settings in Farseer. In this case it might be the LinearDragCoefficient is too large?

Aug 23, 2010 at 1:54 PM

yup.. you nailed it. Thanks!