示例#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;
        }
示例#2
0
        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);
        }
示例#3
0
		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;
		}
示例#4
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;

		}