/** 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.GetBodyA() == body ? joint.GetBodyB() : joint.GetBodyA()); other.RemoveJoint(joint); if (_delayRemoveJoints.Exists(j => j == joint)) { joint._destoryMark = true; } } body._joints.Clear(); RemoveBodyOrDelay(body); _bodies.Remove(body); body._world = null; }
public virtual CCPhysicsBody AddBody(CCPhysicsBody body) { cp.AssertWarn(body != null, "the body can not be nullptr"); if (body.GetWorld() == this) { return(null); } if (body.GetWorld() != null) { body.RemoveFromWorld(); } AddBodyOrDelay(body); _bodies.Add(body); body._world = this; return(body); }
public virtual CCPhysicsBody AddBody(CCPhysicsBody body) { cp.AssertWarn(body != null, "the body can not be nullptr"); if (body.GetWorld() == this) return null; if (body.GetWorld() != null) { body.RemoveFromWorld(); } AddBodyOrDelay(body); _bodies.Add(body); body._world = this; return body; }
/** 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.GetBodyA() == body ? joint.GetBodyB() : joint.GetBodyA()); other.RemoveJoint(joint); if (_delayRemoveJoints.Exists(j => j == joint)) joint._destoryMark = true; } body._joints.Clear(); RemoveBodyOrDelay(body); _bodies.Remove(body); body._world = null; }