This project has moved and is read-only. For the latest updates, please go here.

Change the ZIndex of a BODY on the fly

Topics: Developer Forum
Jun 28, 2010 at 7:13 AM
Hi! Thank you for the awesome engine.
I am from Taiwan and new to the farseer physics and currently work on Silverlight.
I notice that the ZIndex of the Physics Bodies are related to the sequence they been created.
Now I need to change the ZOrder of a BODY on the fly.
For example: To control a hand of a ragdull behind or in front of it's head.
Can I do it? How can I do? Thanks.
Jun 28, 2010 at 9:14 AM
The graphical ZOrder (what you are describing) is done totally outside of the physics engine, meaning Farseer doesn't control this at all. It's up to you and how you make your project. You can attach some property to the fixture.UserData (FP3) or Body.Tag (FP2.x), which you can then use. This way you can put some logic into the Draw method which will allow you to change the order in which the sprites are drawn based on some things happening within your physics environment.
Jun 28, 2010 at 9:34 AM
Edited Jun 28, 2010 at 4:06 PM
Thanks for the reply Jerky. I see your points.
Basically I am coding under Farseer Helper, which allow me to attach the UIElement(Canvas) to the physics body.
Maybe I should go deep to the Draw method which Farseer helper provide and see what I can do to it.
Jun 30, 2010 at 7:18 AM
kokonotsu wrote:
Maybe I should go deep to the Draw method which Farseer helper provide and see what I can do to it.

Exactly. I used the Demo Framework for a long time too. Feel free to add whatever logic you need into the Draw or Update methods as needed. The framework is just there so you can learn from it and start working on things quickly.
Jun 30, 2010 at 7:23 AM
Farseer Helper have already wrapped the Canvas associated to each physics Body by PhysicsSprites.
I just have to set the ZIndexProperty of PhysicsSprites and it works perfectly.
Andy Beaulieu did a great job!