/** Remove all joints from physics world.*/ public virtual void RemoveAllJoints(bool destroy = true) { foreach (var joint in Joints) { RemoveJointOrDelay(joint); joint._world = null; // clean the connection to this joint if (destroy) { if (joint.BodyA != null) { joint.BodyA.RemoveJoint(joint); } if (joint.BodyB != null) { joint.BodyB.RemoveJoint(joint); } // test the distraction is delaied or not if (DelayRemoveJoints.Exists(j => j == joint)) { joint._destoryMark = true; } } } Joints.Clear(); }
/** Remove a body from physics world. */ public virtual void RemoveBody(CCPhysicsBody body) { if (body.GetWorld() != this) { cp.AssertWarn("Physics Warnning: this body doesn't belong to this world"); return; } // destory the body's joints foreach (var joint in body._joints) { // set destroy param to false to keep the iterator available RemoveJoint(joint, false); CCPhysicsBody other = (joint.BodyA == body ? joint.BodyB : joint.BodyA); other.RemoveJoint(joint); if (DelayRemoveJoints.Exists(j => j == joint)) { joint._destoryMark = true; } } body._joints.Clear(); RemoveBodyOrDelay(body); Bodies.Remove(body); body._world = null; }
/** Remove a joint from physics world.*/ public virtual void RemoveJoint(CCPhysicsJoint joint, bool destroy = true) { if (joint.World != this) { if (destroy) { cp.AssertWarn("physics warnning: the joint is not in this world, it won't be destoried utill the body it conntect is destoried"); } return; } RemoveJointOrDelay(joint); Joints.Remove(joint); joint._world = null; // clean the connection to this joint if (destroy) { if (joint.BodyA != null) { joint.BodyA.RemoveJoint(joint); } if (joint.BodyB != null) { joint.BodyB.RemoveJoint(joint); } // test the distraction is delaied or not if (DelayRemoveJoints.Exists(j => j == joint)) { joint._destoryMark = true; } } }