コード例 #1
0
ファイル: CCPhysicsBody.cs プロジェクト: lowsar/CocosSharp
        /*
         * @brief remove a shape from body
         * @param shape the shape to be removed
         * @param reduceMassAndMoment if this is true, the body mass and moment will be reduced by shape. the default is true
         */
        public void RemoveShape(CCPhysicsShape shape, bool reduceMassAndMoment = true)
        {
            if (_shapes.Exists((s) => s == shape))
            {
                // deduce the area, mass and moment
                // area must update before mass, because the density changes depend on it.
                if (reduceMassAndMoment)
                {
                    _area -= shape.GetArea();
                    AddMass(-shape.GetMass());
                    AddMoment(-shape.GetMoment());
                }

                //remove
                if (_world != null)
                {
                    _world.RemoveShape(shape);
                }

                // set shape->_body = nullptr make the shape->setBody will not trigger the _body->removeShape function call.
                shape._body = null;
                shape.SetBody(null);

                _shapes.Remove(shape);
            }
        }
コード例 #2
0
ファイル: CCPhysicsBody.cs プロジェクト: lowsar/CocosSharp
        /*
         * @brief add a shape to body
         * @param shape the shape to be added
         * @param addMassAndMoment if this is true, the shape's mass and moment will be added to body. the default is true
         */
        public virtual CCPhysicsShape AddShape(CCPhysicsShape shape, bool addMassAndMoment = true)
        {
            if (shape == null)
            {
                return(null);
            }

            // add shape to body
            if (!_shapes.Exists((s) => s == shape))
            {
                shape.SetBody(this);

                // calculate the area, mass, and desity
                // area must update before mass, because the density changes depend on it.
                if (addMassAndMoment)
                {
                    _area += shape.GetArea();
                    AddMass(shape.GetMass());
                    AddMoment(shape.GetMoment());
                }

                if (_world != null)
                {
                    _world.AddShape(shape);
                }

                _shapes.Add(shape);

                if (_group != cp.NO_GROUP && shape.GetGroup() == cp.NO_GROUP)
                {
                    shape.SetGroup(_group);
                }
            }

            return(shape);
        }
コード例 #3
0
ファイル: CCPhysicsBody.cs プロジェクト: netonjm/CocosSharp
		/*
		 * @brief remove a shape from body
		 * @param shape the shape to be removed
		 * @param reduceMassAndMoment if this is true, the body mass and moment will be reduced by shape. the default is true
		 */
		public void RemoveShape(CCPhysicsShape shape, bool reduceMassAndMoment = true)
		{
			if (_shapes.Exists((s) => s == shape))
			{
				// deduce the area, mass and moment
				// area must update before mass, because the density changes depend on it.
				if (reduceMassAndMoment)
				{
					_area -= shape.GetArea();
					AddMass(-shape.GetMass());
					AddMoment(-shape.GetMoment());
				}

				//remove
				if (_world != null)
				{
					_world.RemoveShape(shape);
				}

				// set shape->_body = nullptr make the shape->setBody will not trigger the _body->removeShape function call.
				shape._body = null;
				shape.SetBody(null);

				_shapes.Remove(shape);
			}


		}
コード例 #4
0
ファイル: CCPhysicsBody.cs プロジェクト: netonjm/CocosSharp
		/*
		 * @brief add a shape to body
		 * @param shape the shape to be added
		 * @param addMassAndMoment if this is true, the shape's mass and moment will be added to body. the default is true
		 */
		public virtual CCPhysicsShape AddShape(CCPhysicsShape shape, bool addMassAndMoment = true)
		{
			if (shape == null) return null;

			// add shape to body
			if (!_shapes.Exists((s) => s == shape))
			{
				shape.SetBody(this);

				// calculate the area, mass, and desity
				// area must update before mass, because the density changes depend on it.
				if (addMassAndMoment)
				{
					_area += shape.GetArea();
					AddMass(shape.GetMass());
					AddMoment(shape.GetMoment());
				}

				if (_world != null)
				{
					_world.AddShape(shape);
				}

				_shapes.Add(shape);

				if (_group != cp.NO_GROUP && shape.GetGroup() == cp.NO_GROUP)
				{
					shape.SetGroup(_group);
				}
			}

			return shape;
		}