World Reference

Jul 17, 2011 at 1:36 AM

I'm trying to implement an explosion from the Farseer dlls but i can't work out how to pass a world variable from the physics controller. Is this something that i can expose to be able to pass in or can i create one off the physics controller? 

public Explosion(World world)
            : base(world, PhysicsLogicType.Explosion)




Jul 18, 2011 at 3:48 PM

There are two ways to get position from a sprite:

- sprite.Position will give the position in screen coordinates.

- sprite.BodyObject.Position will give the position in Farseer world coordinates.

Additionally, you can translate from screen to world coordinates and back using the utility methods _physicsController.ScreenToWorld and _physicsController.WorldToScreen.

Hope this helps.

Jul 18, 2011 at 10:43 PM

Thanks Andy, I think the Farseer World object is more of a container object similar to the physicsController. It looks like the physicsController is doing the same sort of things, i thought there might be a world object backing it somewhere.


Jul 22, 2011 at 5:38 PM

I'm trying to use _physicsController.WorldToScreen (let's say for your sample you have released) but it asks for a World property. How do I access the world property to pass through this method?

For example:

	_physicsController = LayoutRoot.GetValue(PhysicsControllerMain.PhysicsControllerProperty) as PhysicsControllerMain;
            _physicsController.Initialized += new PhysicsControllerMain.InitializedHandler(physicsController_Initialized);
            _physicsController.Collision += new PhysicsControllerMain.CollisionHandler(physicsController_Collision);
            _physicsController.TimerLoop += new PhysicsControllerMain.TimerLoopHandler(physicsController_TimerLoop);
           _ physicsController.WorldToScreen(???);
How do I pass a the world I am using so that I can just use screen coordinates?

Jul 22, 2011 at 7:30 PM

Hi Mike,

Just a reminder, Farseer uses its own coordinate system in "World" coordinates. But as a Silverlight developer, we are used to positioning things at specific X,Y (or Left, Top) coordinates.

If you just need the screen position of a sprite, you can use the Sprite.Position property - there is no need to translate to or from World coordinates. Sprite.Position will return the equivalent Left, Top properties of the element.

But for more advanced stuff, you may need to get at World coordinates. For WorldToScreen, the world parameter is a Vector2 (x,y) position in Farseer's world coordinates. For example, for a sprite's BodyObject.Postion property.

hope this helps.