Need help disposing of a joint when broken...

Jul 6, 2009 at 8:13 PM

Hi

After a while of struggling I have got my game to figure out when a joint is broken, and I am able to produce an overall number of joints that have broken. The problem is that when the method/sub-routine (please can someone remind me of what they are called in C#) is called by the .Broke event of a joint, it works but I can work out how to dispose of the joint that called it as all my joints are in an array. I don't know how I can pass an int when it .Broke event is fired.

Can anyone help me?

Thanks

Coordinator
Jul 6, 2009 at 9:35 PM
Edited Jul 6, 2009 at 9:36 PM

When you subscribe to the Broke event on the joint, you give it a function (or method as you called it).

The Broke event has two arguments: "this" and EventArgs.Empty

You can completely ignore EventArgs.Empty as it does nothing at all. "this" argument is what you want since it contains a reference to the joint that broke. Do something like this:

 

private void JointBroke(object sender, EventArgs e)
{
  Joint joint = (Joint)sender;
  joint.Dispose();
}

 

You can't send an int directly with the event, but you can store it in the joint. All joints contain a Tag property that can contain anything you like. You access it like this:

 

private void JointBroke(object sender, EventArgs e)
{
Joint joint = (Joint)sender;
int myInt = (int)joint.Tag;
}

 

Jul 6, 2009 at 9:40 PM

Didn't think of "Joint joint = (Joint)sender;"

Thank you genbox!