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

genbox, please help me

Topics: Developer Forum, User Forum
Jul 20, 2009 at 6:52 AM

I would like to disappear after a collision of two objects, there is the Examples on Silverlight?

Jul 20, 2009 at 2:30 PM

You have two options when it comes to removing geometries/not drawing them.

1. Remove the geometry from the physics simulator in the collision by doing this:

private void OnCollision(geom geomA, geom geomB, ContactList list)

Calling .Dispose() on a body or geometry will mark it as disposed. Once the physics simulator traverse the list of geometries and bodies, it will automatically remove the disposed objects and clean up after them.


2. Disable the body and stop drawing it.

When you detect the collision you simply disable the body. You can set Body.Enabled = false and it will not be updated in the physics engine. If you ever need the body again, you simply enable it again. In your drawing code you need to check if the body is enabled before drawing it. The advantage of disabling it instead of removing it is that you can reuse the body and geometry. You can also save some resources using this method if you respawn geometries (like bullets out of a gun).

Jul 20, 2009 at 3:56 PM

Thank you very much

Jul 20, 2009 at 11:07 PM

As a sidenote, if you use option 2, you may want to set body.enabled = false AFTER the physics simulator update.  For example, I have bullets that I disabled OnCollision.  The objects hit weren't affected by the bullet.  I instead set a flag ToDestroy = true OnCollision, then check after the physics simulator update for that flag, and disable it then.