/** 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 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(); }
public virtual void UpdateJoints() { if (Info.IsLocked()) { return; } CCPhysicsJoint[] addCopy = new CCPhysicsJoint[DelayAddJoints.Count]; DelayAddJoints.CopyTo(addCopy); DelayAddJoints.Clear(); foreach (var joint in addCopy) { DoAddJoint(joint); } CCPhysicsJoint[] removeCopy = new CCPhysicsJoint[DelayRemoveJoints.Count]; DelayRemoveJoints.CopyTo(removeCopy); DelayRemoveJoints.Clear(); foreach (var joint in removeCopy) { DoRemoveJoint(joint); if (joint._destoryMark) { //delete joint; } } }
public virtual void RemoveJointOrDelay(CCPhysicsJoint joint) { var it = DelayAddJoints.Find(j => j == joint); if (it != null) { DelayAddJoints.Remove(it); } if (Info.IsLocked()) { if (!DelayAddJoints.Exists(j => j == joint)) { DelayRemoveJoints.Add(joint); DelayDirty = true; } } else { DoRemoveJoint(joint); } }
/** 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; } } }