How to drag a body

Sep 3, 2011 at 3:40 PM

Hi I'm having some problems to drag a body by touching the screen (on windows Phone). I know that I can't just change the position. Can anyone tell me How can I do it? :( Thanks!

Sep 7, 2011 at 2:40 PM
des91iraq wrote:

hi

this is my implementation for Mouse Joint

 

       private FixedMouseJoint fixedMouseJoint;


       public void MouseJointHandler()
        {
            Vector2 position = new Vector2(Mouse.GetState().X / MeterInPixel, Mouse.GetState().Y / MeterInPixel);
            if (Mouse.GetState().LeftButton == ButtonState.Pressed && fixedMouseJoint == null)
            {
                fixture = world.TestPoint(position);
                if (fixture != null)
                {
                    Body body = fixture.Body;
                    fixedMouseJoint = new FixedMouseJoint(body, position);
                    fixedMouseJoint.MaxForce = 1000.0f * body.Mass;
                    world.AddJoint(fixedMouseJoint);
                    body.Awake = true;

                }
            }

            if (Mouse.GetState().LeftButton == ButtonState.Released && fixedMouseJoint != null)
            {
                world.RemoveJoint(fixedMouseJoint);
                fixedMouseJoint = null;
            }

            if (fixedMouseJoint != null)
            {
                fixedMouseJoint.WorldAnchorB = position;
            }
        }

this my reply in this post with mouse in Windows you can modify it to work with touch screen

http://farseerphysics.codeplex.com/discussions/267958