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

FPE 3.3 breakable bodies & OnCollision remove body

Topics: Developer Forum, Project Management Forum, User Forum
Mar 21, 2011 at 2:25 PM

Hi Guys,

Version 3.3 looks very neat as far as I have seen. I have a couple of questions which I can't get my head around and which I have had for a while since version 3.3 has been on development.

First question has to do with breakablebodies:

In the AdvancedSimpleSamples there is a good sample on how to get a body from a drawn shape and then break it. So far it is all good but I am trying to create something like a stack of bricks like but I can see that so far it creates the breakable body but it does not apply a texture to it. It still creates the breakable fixtures but not a body and are read only so when trying to apply a texture to it, it does not work. Making the code in the Draw function very complex and as for what I can see just not possible to do the texture drawing.

If anyone knows how to get the brick to be drawn and then break it after a "collision", it would help.

Second question has to do with evenst after collision:

I have got the OnCollision bool working so when 2 bodies collide, the collision is detected but then when I try to remove the body from the world by doing the World.DestroyBody(body), it just removes the fixtures but not the texture that was applied to it.


Thanks again and hope I can get a help with these questions.

Mar 21, 2011 at 4:14 PM

This really is out of scope for this forum. Please keep in mind Farseer is not about drawing anything and the samples we provide are not part of the physics engine. The samples main goal is to show off all of Farseer features. As a nice side effect they provide one or two methods of drawing physical objects. That is however not a supported part of Farseer Physics and the drawing code is subject to change on very short notice, so it is probably nothing you want to base your own game on. It is ok for prototyping but nothing more.

One goal in the examples for instance is to somewhat show the user what is going on in Farseer internally by visualizing joint interactions etc. In a real game you probably want to hide as much of the internal physics stuff as possible to make things look more natural.

Your drawing code should be highly dependent on your actual game and we can't provide support for every possible solution out there. It will look quite different for example whether you do a lot of sprite based drawing or use 3D models for a 2.5D style game.

Farseer 3.2 used a material system, which was easy to use for us but unfortunately heightened the impression that Farseer and the drawing system were somewhat two parts of the same engine and tightly coupled. Therefore it was replaced with spritebatch based drawing where possible in 3.3. That results in a lot more rendering code, which hopefully is easier to understand and follow for people just starting with Farseer and XNA.

That said: Drawing breakable bodies is fairly complex and will require quite some effort. And as with all drawing you will need to keep track of which texture/primitives/objects/etc...  you would like to have attached to which Fixture for yourself. The same applies to your body removal problem: Bodies and graphical representations are decoupled and therefore you have to get rid of any graphical objects for yourself. You can however use a bodies/fixtures UserData pointer to point to any object you like... for instance your sprite/texture/class... so when you destroy a body somewhere in your code, just remember to destroy the object the UserData points to first in proper way and you should be fine.