Taking action on collissions

Aug 20, 2010 at 9:04 PM


From what I think I understand of collissions, you are given the object reporting the collission, and the object it collides with, right?

I have projectiles I want to remove on collission. If I have the string name of the object from teh collision, how do you tie that back to it's corresponding framework elements in the canvas?

I think I see that farseer assigns it's own names inteernally. I know the names I am giving to what I add to the canvas, but they are different.

What's the best way to go about this?



Aug 21, 2010 at 8:20 PM

Say I have a usercontrol that I want to 'destroy', do RemoveElementAction, or PhysicsDestroyObjectBehavoir come into play?

I need to get to a point where I am programatically adding and removing things from my game, so I can keep performance up.

Jan 31, 2011 at 2:59 PM

Hi Roger,

I am also looking for something similar, to remove physics objects programatically.

Did you get it to work?

Muy problem is the programatically added physics behaviour doesnt seem to adapt to the newer boundries of resized physics object. So trying to remove the physics object and have to add it back.

Any workarounds?


Feb 1, 2011 at 11:04 AM

In the latest version of the physics helper it's something like:


You can use the sprite name from the collision event and that will remove it from both the physics engine and the silverlight screen.



Feb 4, 2011 at 2:33 AM

Hi Mccabela,

I have tried the following code to delete a System.Windows.Shapes.Line object testLine. It has the name testLine. This approach didn't work either.





Can System.Windows.Shapes.Line be considered as a sprite? If not then how should we proceed for a Line object?

Feb 4, 2011 at 6:17 AM

HI Anilmaddala,

I would suggest checking the PhysicsObjects in the physicsController to verify the name you're using to remove the object is correct.

I got caught out a few times as when you add an object to the physics helper is can auto generate the name of the object.

You should be able to add a line, but i'm not 100% sure.



Feb 4, 2011 at 12:47 PM

Unfortunately I don't think a line will work.  The boundary detection handles ellipses (circles really, equal height and width), rectangles, and convex polygons. The closest you could come to a line is a very skinny rectangle :)

Farseer 3 itself could create lines, you would just need to call the Farseer classes directly without using the Physics Helper.

Feb 5, 2011 at 8:50 PM

Hi Andy,

System.Windows.Shapes.Line is working fine.

I went through your source code and am now able to delete the the physics object also. Below is the code:

	this.Canvas.Children.Remove(this.Canvas.FindName(this.testLine.Name) as UIElement);

However i have a new problem of adding it back. Even though i add it through code like i did previously, its still not getting added as a physics object. Maybe some issue with Object Name. Still looking into this.

Is there any better way of doing this? I want to change the coordinates of the line and it should still behave like a physics object.

If i directly change the coordinates of the line, the UI line changes but an invisible physics line gets left behind at its previous position. Please help me.

Thank you.