Esempio n. 1
0
        /** 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;
        }
Esempio n. 2
0
        /** Distory the joint*/
        public void Destroy()
        {
            // remove the joint and delete it.
            if (_world != null)
            {
                _world.RemoveJoint(this, true);
            }
            else
            {
                if (_bodyA != null)
                {
                    _bodyA.RemoveJoint(this);
                }

                if (_bodyB != null)
                {
                    _bodyB.RemoveJoint(this);
                }
            }
        }