• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Dynamics.b2FixtureDef类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Box2D.Dynamics.b2FixtureDef的典型用法代码示例。如果您正苦于以下问题:C# b2FixtureDef类的具体用法?C# b2FixtureDef怎么用?C# b2FixtureDef使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



b2FixtureDef类属于Box2D.Dynamics命名空间,在下文中一共展示了b2FixtureDef类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Keyboard

        public override void Keyboard(char key)
        {
            switch (key)
            {
                case ',':
                    if (m_bullet != null)
                    {
                        m_world.DestroyBody(m_bullet);
                        m_bullet = null;
                    }
                    {
                        b2CircleShape shape = new b2CircleShape();
                        shape.Radius = 0.25f;

                        b2FixtureDef fd = new b2FixtureDef();
                        fd.shape = shape;
                        fd.density = 20.0f;
                        fd.restitution = 0.05f;

                        b2BodyDef bd  = new b2BodyDef();
                        bd.type = b2BodyType.b2_dynamicBody;
                        bd.bullet = true;
                        bd.position.Set(-31.0f, 5.0f);

                        m_bullet = m_world.CreateBody(bd);
                        m_bullet.CreateFixture(fd);

                        m_bullet.LinearVelocity = new b2Vec2(400.0f, 0.0f);
                    }
                    break;
            }
        }
开发者ID:h7ing,项目名称:CocosSharp,代码行数:32,代码来源:VerticalStack.cs


示例2: VaryingRestitution

        public VaryingRestitution()
        {
            {
                b2BodyDef bd  = new b2BodyDef();
                b2Body ground = m_world.CreateBody(bd);

                b2EdgeShape shape = new b2EdgeShape();
                shape.Set(new b2Vec2(-40.0f, 0.0f), new b2Vec2(40.0f, 0.0f));
                ground.CreateFixture(shape, 0.0f);
            }

            {
                b2CircleShape shape = new b2CircleShape();
                shape.Radius = 1.0f;

                b2FixtureDef fd = new b2FixtureDef();
                fd.shape = shape;
                fd.density = 1.0f;

                float[] restitution = {0.0f, 0.1f, 0.3f, 0.5f, 0.75f, 0.9f, 1.0f};

                for (int i = 0; i < 7; ++i)
                {
                    b2BodyDef bd  = new b2BodyDef();
                    bd.type = b2BodyType.b2_dynamicBody;
                    bd.position.Set(-10.0f + 3.0f * i, 20.0f);

                    b2Body body = m_world.CreateBody(bd);

                    fd.restitution = restitution[i];
                    body.CreateFixture(fd);
                }
            }
        }
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:34,代码来源:VaryingRestitution.cs


示例3: CreateNinja

		void CreateNinja() {
			
			
			spriteImageName = String.Format("{0}_standing", baseImageName); 

			onGround = false;
			
			// Define the dynamic body.
			var bodyDef = new b2BodyDef();
			bodyDef.type = b2BodyType.b2_staticBody; //or you could use b2DynamicBody to start the ninja as dynamic
			
			bodyDef.position.Set(initialLocation.X/Constants.PTM_RATIO, initialLocation.Y/Constants.PTM_RATIO);
			
			var shape = new b2CircleShape();
			var radiusInMeters = (40 / Constants.PTM_RATIO) * 0.5f; //increase or decrease 40 for a different circle size definition
			
			shape.Radius = radiusInMeters;
			
			
			// Define the dynamic body fixture.
			var fixtureDef = new b2FixtureDef();
			fixtureDef.shape = shape;	
			fixtureDef.density = 1.0f;
			fixtureDef.friction = 1.0f;
			fixtureDef.restitution =  0.1f;
			
			CreateBodyWithSpriteAndFixture(theWorld, bodyDef, fixtureDef, spriteImageName);
			
		}
开发者ID:460189852,项目名称:cocos-sharp-samples,代码行数:29,代码来源:Ninja.cs


示例4: InitPhysics

        void InitPhysics()
        {
            var gravity = new b2Vec2(0.0f, -10.0f);
            world = new b2World(gravity);

            world.SetAllowSleeping(true);
            world.SetContinuousPhysics(true);

            var def = new b2BodyDef();
            def.allowSleep = true;
            def.position = b2Vec2.Zero;
            def.type = b2BodyType.b2_staticBody;

            b2Body groundBody = world.CreateBody(def);
            groundBody.SetActive(true);

            b2EdgeShape groundBox = new b2EdgeShape();
            groundBox.Set(b2Vec2.Zero, new b2Vec2(900, 100));

            b2FixtureDef fd = new b2FixtureDef();
            fd.friction = 0.3f;
            fd.restitution = 0.1f;
            fd.shape = groundBox;

            groundBody.CreateFixture(fd);
        }
开发者ID:460189852,项目名称:cocos-sharp-samples,代码行数:26,代码来源:IntroLayer.cs


示例5: JumpPad

        public JumpPad(b2Vec2 JumpImpuls, CCPoint Position, b2World gameWorld)
        {
            this.Texture = new CCTexture2D ("jumppad");
            this.Scale = SpriteScale;
            this.Position = Position;
            this.IsAntialiased = false;

            jumpImpuls = JumpImpuls;
            totalJumps = 0;

            //box2d
            b2BodyDef jumpPadDef = new b2BodyDef ();
            jumpPadDef.type = b2BodyType.b2_kinematicBody;
            jumpPadDef.position = new b2Vec2 ((Position.X + this.ScaledContentSize.Width/2)/PhysicsHandler.pixelPerMeter, (Position.Y + this.ScaledContentSize.Height/4) / PhysicsHandler.pixelPerMeter);
            JumpPadBody = gameWorld.CreateBody (jumpPadDef);

            b2PolygonShape jumpPadShape = new b2PolygonShape ();
            jumpPadShape.SetAsBox ((float)this.ScaledContentSize.Width / PhysicsHandler.pixelPerMeter / 2, (float)this.ScaledContentSize.Height / PhysicsHandler.pixelPerMeter / 4);// /4 weil die hitbox nur die hälfte der textur ist

            b2FixtureDef jumpPadFixture = new b2FixtureDef ();
            jumpPadFixture.shape = jumpPadShape;
            jumpPadFixture.density = 0.0f; //Dichte
            jumpPadFixture.restitution = 0f; //Rückprall
            jumpPadFixture.friction = 0f;
            jumpPadFixture.userData = WorldFixtureData.jumppad;
            JumpPadBody.CreateFixture (jumpPadFixture);
            //
        }
开发者ID:Nuckal777,项目名称:mapKnight,代码行数:28,代码来源:JumpPad.cs


示例6: SensorTest

        public SensorTest()
        {
            {
                b2BodyDef bd  = new b2BodyDef();
                b2Body ground = m_world.CreateBody(bd);

                {
                    b2EdgeShape shape = new b2EdgeShape();
                    shape.Set(new b2Vec2(-40.0f, 0.0f), new b2Vec2(40.0f, 0.0f));
                    ground.CreateFixture(shape, 0.0f);
                }

#if false
            {
                b2FixtureDef sd = new b2FixtureDef();
                sd.SetAsBox(10.0f, 2.0f, new b2Vec2(0.0f, 20.0f), 0.0f);
                sd.isSensor = true;
                m_sensor = ground.CreateFixture(sd);
            }
#else
                {
                    b2CircleShape shape = new b2CircleShape();
                    shape.Radius = 5.0f;
                    shape.Position = new b2Vec2(0.0f, 10.0f);

                    b2FixtureDef fd = new b2FixtureDef();
                    fd.shape = shape;
                    fd.isSensor = true;
                    m_sensor = ground.CreateFixture(fd);
                }
#endif
            }

            {
                b2CircleShape shape = new b2CircleShape();
                shape.Radius = 1.0f;

                for (int i = 0; i < e_count; ++i)
                {
                    b2BodyDef bd  = new b2BodyDef();
                    bd.type = b2BodyType.b2_dynamicBody;
                    bd.position.Set(-10.0f + 3.0f * i, 20.0f);
                    bd.userData = i; //  m_touching[i];

                    m_touching[i] = false;
                    m_bodies[i] = m_world.CreateBody(bd);

                    m_bodies[i].CreateFixture(shape, 1.0f);
                }
            }
        }
开发者ID:h7ing,项目名称:CocosSharp,代码行数:51,代码来源:SensorTest.cs


示例7: Confined

        public Confined()
        {
            {
                b2BodyDef bd  = new b2BodyDef();
                b2Body ground = m_world.CreateBody(bd);

                b2EdgeShape shape = new b2EdgeShape();

                // Floor
                shape.Set(new b2Vec2(-10.0f, 0.0f), new b2Vec2(10.0f, 0.0f));
                ground.CreateFixture(shape, 0.0f);

                // Left wall
                shape.Set(new b2Vec2(-10.0f, 0.0f), new b2Vec2(-10.0f, 20.0f));
                ground.CreateFixture(shape, 0.0f);

                // Right wall
                shape.Set(new b2Vec2(10.0f, 0.0f), new b2Vec2(10.0f, 20.0f));
                ground.CreateFixture(shape, 0.0f);

                // Roof
                shape.Set(new b2Vec2(-10.0f, 20.0f), new b2Vec2(10.0f, 20.0f));
                ground.CreateFixture(shape, 0.0f);
            }

            float radius = 0.5f;
            b2CircleShape shape1 = new b2CircleShape();
            shape1.Position = b2Vec2.Zero;
            shape1.Radius = radius;

            b2FixtureDef fd = new b2FixtureDef();
            fd.shape = shape1;
            fd.density = 1.0f;
            fd.friction = 0.1f;

            for (int j = 0; j < e_columnCount; ++j)
            {
                for (int i = 0; i < e_rowCount; ++i)
                {
                    b2BodyDef bd  = new b2BodyDef();
                    bd.type = b2BodyType.b2_dynamicBody;
                    bd.position.Set(-10.0f + (2.1f * j + 1.0f + 0.01f * i) * radius, (2.0f * i + 1.0f) * radius);
                    b2Body body = m_world.CreateBody(bd);

                    body.CreateFixture(fd);
                }
            }

            m_world.Gravity = new b2Vec2(0.0f, 0.0f);
        }
开发者ID:h7ing,项目名称:CocosSharp,代码行数:50,代码来源:Confined.cs


示例8: VerticalStack

        //public const int e_columnCount = 1;
        //public const int e_rowCount = 1;

        public VerticalStack()
        {
            {
                b2BodyDef bd  = new b2BodyDef();
                b2Body ground = m_world.CreateBody(bd);

                b2EdgeShape shape = new b2EdgeShape();
                shape.Set(new b2Vec2(-40.0f, 0.0f), new b2Vec2(40.0f, 0.0f));
                ground.CreateFixture(shape, 0.0f);

                shape.Set(new b2Vec2(20.0f, 0.0f), new b2Vec2(20.0f, 20.0f));
                ground.CreateFixture(shape, 0.0f);
            }

            float[] xs = {0.0f, -10.0f, -5.0f, 5.0f, 10.0f};

            for (int j = 0; j < e_columnCount; ++j)
            {
                b2PolygonShape shape = new b2PolygonShape();
                shape.SetAsBox(0.5f, 0.5f);

                b2FixtureDef fd = new b2FixtureDef();
                fd.shape = shape;
                fd.density = 1.0f;
                fd.friction = 0.3f;

                for (int i = 0; i < e_rowCount; ++i)
                {
                    b2BodyDef bd  = new b2BodyDef();
                    bd.type = b2BodyType.b2_dynamicBody;

                    int n = j * e_rowCount + i;
                    Debug.Assert(n < e_rowCount * e_columnCount);
                    m_indices[n] = n;
                    bd.userData = m_indices[n];

                    float x = 0.0f;
                    //float32 x = RandomFloat(-0.02f, 0.02f);
                    //float32 x = i % 2 == 0 ? -0.025f : 0.025f;
                    bd.position.Set(xs[j] + x, 0.752f + 1.54f * i);
                    b2Body body = m_world.CreateBody(bd);

                    m_bodies[n] = body;

                    body.CreateFixture(fd);
                }
            }

            m_bullet = null;
        }
开发者ID:h7ing,项目名称:CocosSharp,代码行数:53,代码来源:VerticalStack.cs


示例9: CreatePlatform

		void CreatePlatform() {
			
			// Define the dynamic body.
			var bodyDef = new b2BodyDef();
			bodyDef.type = b2BodyType.b2_staticBody; //or you could use b2_staticBody
			
			bodyDef.position.Set(initialLocation.X/Constants.PTM_RATIO, initialLocation.Y/Constants.PTM_RATIO);

			var shape = new b2PolygonShape();
			
			var num = 4;
			b2Vec2[] vertices = {
				new b2Vec2(-102.0f / Constants.PTM_RATIO, -49.5f / Constants.PTM_RATIO),
				new b2Vec2(-113.0f / Constants.PTM_RATIO, -81.5f / Constants.PTM_RATIO),
				new b2Vec2(113.0f / Constants.PTM_RATIO, -84.5f / Constants.PTM_RATIO),
				new b2Vec2(106.0f / Constants.PTM_RATIO, -47.5f / Constants.PTM_RATIO)
			};
			
			shape.Set(vertices, num);
			
			
			// Define the dynamic body fixture.
			var fixtureDef = new b2FixtureDef();
			fixtureDef.shape = shape;	
			fixtureDef.density = 1.0f;
			fixtureDef.friction = 0.3f;
			fixtureDef.restitution =  0.1f;
			
			CreateBodyWithSpriteAndFixture(theWorld, bodyDef, fixtureDef, spriteImageName);
			
			//CONTINUING TO ADD BODY SHAPE....
			
			// THIS IS THE Sling base....
			
			//row 1, col 1
			var num2 = 4;
			b2Vec2[] vertices2 = {
				new b2Vec2(41.0f / Constants.PTM_RATIO, -6.5f / Constants.PTM_RATIO),
				new b2Vec2(35.0f / Constants.PTM_RATIO, -57.5f / Constants.PTM_RATIO),
				new b2Vec2(57.0f / Constants.PTM_RATIO, -65.5f / Constants.PTM_RATIO),
				new b2Vec2(49.0f / Constants.PTM_RATIO, -7.5f / Constants.PTM_RATIO)
			};
			
			shape.Set(vertices2, num2);
			fixtureDef.shape = shape;
			body.CreateFixture(fixtureDef);
			
		}
开发者ID:alegogit,项目名称:AngryNinjas,代码行数:48,代码来源:StartPlatform.cs


示例10: CreateBodyWithSpriteAndFixture

        protected void CreateBodyWithSpriteAndFixture(b2World world, b2BodyDef bodyDef,
                                                       b2FixtureDef fixtureDef, string spriteName)
        {
            // this is the meat of our class, it creates (OR recreates) the body in the world with the body definition, fixture definition and sprite name

            RemoveBody(); //if remove the body if it already exists
            RemoveSprite(); //if remove the sprite if it already exists

            sprite = new CCSprite(spriteName);
            AddChild(sprite);

            body = world.CreateBody(bodyDef);
            body.UserData = this;

            if (fixtureDef != null)
                body.CreateFixture(fixtureDef);
        }
开发者ID:460189852,项目名称:cocos-sharp-samples,代码行数:17,代码来源:BodyNode.cs


示例11: CreateGround

		private void CreateGround()
		{
			// Define the dynamic body.
			var bodyDef = new b2BodyDef();
			bodyDef.type = b2BodyType.b2_staticBody; //or you could use b2_staticBody
			
			bodyDef.position.Set(initialLocation.X/Constants.PTM_RATIO, initialLocation.Y/Constants.PTM_RATIO);
			
			b2PolygonShape shape = new b2PolygonShape();
			
			int num = 4;
			b2Vec2[] vertices = {
				new b2Vec2(-1220.0f / Constants.PTM_RATIO, 54.0f / Constants.PTM_RATIO),
				new b2Vec2(-1220.0f / Constants.PTM_RATIO, -52.0f / Constants.PTM_RATIO),
				new b2Vec2(1019.0f / Constants.PTM_RATIO, -52.0f / Constants.PTM_RATIO),
				new b2Vec2(1019.0f / Constants.PTM_RATIO, 54.0f / Constants.PTM_RATIO)
			};
			
			shape.Set(vertices, num);
			
			
			// Define the dynamic body fixture.
			var fixtureDef = new b2FixtureDef();
			fixtureDef.shape = shape;	
			fixtureDef.density = 1.0f;
			fixtureDef.friction = 1.0f;
			fixtureDef.restitution =  0.1f;
			
			CreateBodyWithSpriteAndFixture(theWorld, bodyDef, fixtureDef, spriteImageName);
			
			if (!TheLevel.SharedLevel.IS_RETINA)
			{
				//non retina adjustment
				sprite.ScaleX = 1.05f;
				
			} else {
				
				// retina adjustment
				
				sprite.ScaleX = 2.05f;
				sprite.ScaleY = 2.0f;
			}

		}
开发者ID:headinthebox,项目名称:cocos-sharp-samples,代码行数:44,代码来源:GroundPlane.cs


示例12: Platform

        public Platform(List<CCPoint> platformWaypoints, int platformSpeed, Container gameContainer)
        {
            this.Texture = new CCTexture2D("platform");
            this.Scale = SpriteScale;
            this.IsAntialiased = false;

            this.Position = platformWaypoints [0];
            Waypoints = platformWaypoints;
            speed = platformSpeed;
            //umso geringer der speed umso schneller die platform

            CurrentWaypoint = 0;
            wayToMove = new CCSize (Waypoints [CurrentWaypoint + 1].X - Waypoints [CurrentWaypoint].X, Waypoints [CurrentWaypoint + 1].Y - Waypoints [CurrentWaypoint].Y);

            //box2d
            b2BodyDef platformDef = new b2BodyDef ();
            platformDef.type = b2BodyType.b2_kinematicBody;
            platformDef.position = new b2Vec2 (Waypoints[CurrentWaypoint].X / PhysicsHandler.pixelPerMeter, Waypoints[CurrentWaypoint].Y / PhysicsHandler.pixelPerMeter);
            platformBody = gameContainer.physicsHandler.gameWorld.CreateBody (platformDef);

            b2PolygonShape platformShape = new b2PolygonShape ();
            platformShape.SetAsBox ((float)this.ScaledContentSize.Width / PhysicsHandler.pixelPerMeter / 2, (float)this.ScaledContentSize.Height / PhysicsHandler.pixelPerMeter / 2);

            b2FixtureDef platformFixture = new b2FixtureDef ();
            platformFixture.shape = platformShape;
            platformFixture.density = 0.0f; //Dichte
            platformFixture.restitution = 0f; //Rückprall
            platformFixture.userData = WorldFixtureData.platform;
            platformBody.CreateFixture (platformFixture);
            //

            this.Position = new CCPoint (platformBody.Position.x * PhysicsHandler.pixelPerMeter, platformBody.Position.y * PhysicsHandler.pixelPerMeter);

            progressionX = wayToMove.Width/ (float)speed;
            progressionY =  wayToMove.Height/(float)speed ;
            if (float.IsInfinity (progressionX))
                progressionX = 0;
            if (float.IsInfinity (progressionY))
                progressionY = 0;
            b2Vec2 Velocity = platformBody.LinearVelocity;
            Velocity.y = progressionY;
            Velocity.x = progressionX;
            platformBody.LinearVelocity = Velocity;
        }
开发者ID:Nuckal777,项目名称:mapKnight,代码行数:44,代码来源:Platform.cs


示例13: Chain

        public Chain()
        {
            b2Body ground = null;
            {
                b2BodyDef bd  = new b2BodyDef();
                ground = m_world.CreateBody(bd);

                b2EdgeShape shape = new b2EdgeShape();
                shape.Set(new b2Vec2(-40.0f, 0.0f), new b2Vec2(40.0f, 0.0f));
                ground.CreateFixture(shape, 0.0f);
            }

            {
                b2PolygonShape shape = new b2PolygonShape();
                shape.SetAsBox(0.6f, 0.125f);

                b2FixtureDef fd = new b2FixtureDef();
                fd.shape = shape;
                fd.density = 20.0f;
                fd.friction = 0.2f;

                b2RevoluteJointDef jd = new b2RevoluteJointDef();
                jd.CollideConnected = false;

                const float y = 25.0f;
                b2Body prevBody = ground;
                for (int i = 0; i < 30; ++i)
                {
                    b2BodyDef bd  = new b2BodyDef();
                    bd.type = b2BodyType.b2_dynamicBody;
                    bd.position.Set(0.5f + i, y);
                    b2Body body = m_world.CreateBody(bd);
                    body.CreateFixture(fd);

                    b2Vec2 anchor = new b2Vec2(i, y);
                    jd.Initialize(prevBody, body, anchor);
                    m_world.CreateJoint(jd);

                    prevBody = body;
                }
            }
        }
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:42,代码来源:Chain.cs


示例14: CreateCircle

        public void CreateCircle()
        {
            float radius = 2.0f;
            b2CircleShape shape = new b2CircleShape();
            shape.Position = b2Vec2.Zero;
            shape.Radius = radius;

            b2FixtureDef fd = new b2FixtureDef();
            fd.shape = shape;
            fd.density = 1.0f;
            fd.friction = 0.0f;

            b2Vec2 p = new b2Vec2(Rand.RandomFloat(), 3.0f + Rand.RandomFloat());
            b2BodyDef bd  = new b2BodyDef();
            bd.type = b2BodyType.b2_dynamicBody;
            bd.position = p;
            //bd.allowSleep = false;
            b2Body body = m_world.CreateBody(bd);

            body.CreateFixture(fd);
        }
开发者ID:h7ing,项目名称:CocosSharp,代码行数:21,代码来源:Confined.cs


示例15: BoxProp

        public BoxProp(
               b2World b2world,

             double[] size,
             double[] position

            )
        {
            /*
            static rectangle shaped prop
     
                pars:
                size - array [width, height]
                position - array [x, y], in world meters, of center
            */
            this.size = size;

            //initialize body
            var bdef = new b2BodyDef();
            bdef.position = new b2Vec2(position[0], position[1]);
            bdef.angle = 0;
            bdef.fixedRotation = true;
            this.body = b2world.CreateBody(bdef);

            //initialize shape
            var fixdef = new b2FixtureDef();

            var shape = new b2PolygonShape();
            fixdef.shape = shape;

            shape.SetAsBox(this.size[0] / 2, this.size[1] / 2);

            fixdef.restitution = 0.4; //positively bouncy!



            this.body.CreateFixture(fixdef);
        }
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:38,代码来源:BoxProp.cs


示例16: Create

        private void Create(int index)
        {
            if (m_bodies[m_bodyIndex] != null)
            {
                m_world.DestroyBody(m_bodies[m_bodyIndex]);
                m_bodies[m_bodyIndex] = null;
            }

            b2BodyDef bd  = new b2BodyDef();

            float x = Rand.RandomFloat(-10.0f, 10.0f);
            float y = Rand.RandomFloat(10.0f, 20.0f);
            bd.position.Set(x, y);
            bd.angle = Rand.RandomFloat(-b2Settings.b2_pi, b2Settings.b2_pi);
            bd.type = b2BodyType.b2_dynamicBody;

            if (index == 4)
            {
                bd.angularDamping = 0.02f;
            }

            m_bodies[m_bodyIndex] = m_world.CreateBody(bd);

            if (index < 4)
            {
                b2FixtureDef fd = new b2FixtureDef();
                fd.shape = m_polygons[index];
                fd.friction = 0.3f;
                fd.density = 20.0f;
                m_bodies[m_bodyIndex].CreateFixture(fd);
            }
            else
            {
                b2FixtureDef fd = new b2FixtureDef();
                fd.shape = m_circle;
                fd.friction = 0.3f;
                fd.density = 20.0f;
                m_bodies[m_bodyIndex].CreateFixture(fd);
            }

            m_bodyIndex = (m_bodyIndex + 1) % e_maxBodies;
        }
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:42,代码来源:EdgeShapes.cs


示例17: AddGround

        /// <summary>
        /// ��һ����ӵ���
        /// �ڶ�������box-2d�������潫������Ϊ��̬������ӵ�����������
        /// </summary>
        private void AddGround()
        {
            ground = CCSprite.spriteWithFile("imgs/ground/ground");
            ground.position = new CCPoint(ground.contentSize.width / 2, ground.contentSize.height / 2);

            b2BodyDef groundBodyDef = new b2BodyDef();
            groundBodyDef.position = new b2Vec2(ground.contentSize.width / PTM_RATIO / 2, ground.contentSize.height / PTM_RATIO / 2);
            groundBodyDef.userData = ground;

            // ��������Ӱ�죬�����˶�
            groundBodyDef.type = b2BodyType.b2_staticBody;

            // ����ground���˶���ʹ���ٶ���bird�ķ����ٶ�һ��
            var action1 = CCMoveTo.actionWithDuration(ground.contentSize.width / (4 * PTM_RATIO * flySpeed),
                                                      new CCPoint(ground.contentSize.width / 4, ground.position.y));
            var action2 = CCMoveTo.actionWithDuration(0, new CCPoint(ground.contentSize.width / 2, ground.position.y));
            var action = CCSequence.actionOneTwo(action1, action2);
            var repeatAction = CCRepeatForever.actionWithAction(action);
            repeatAction.tag = 0;
            ground.runAction(repeatAction);

            b2Body groundBody = world.CreateBody(groundBodyDef);
            b2PolygonShape groundBox = new b2PolygonShape();
            b2FixtureDef boxShapeDef = new b2FixtureDef();
            boxShapeDef.shape = groundBox;
            groundBox.SetAsBox(ground.contentSize.width / PTM_RATIO / 2, ground.contentSize.height / PTM_RATIO / 2);
            groundBody.CreateFixture(boxShapeDef);
            this.addChild(ground);
        }
开发者ID:hj458377603,项目名称:FlappyBird,代码行数:33,代码来源:GameScene.cs


示例18: AddBird

        /// <summary>
        /// ��һ���ڳ��������һ����̬��bird����
        /// �ڶ�����bird�����ж���
        /// ����������box-2d����������bird�������������
        /// </summary>
        private void AddBird()
        {
            CCSprite bird = CCSprite.spriteWithFile("imgs/bird/bird_01");
            bird.rotation = -15;

            // bird���ж���֡����
            List<CCSpriteFrame> frames = new List<CCSpriteFrame>();

            for (int i = 1; i < 3; i++)
            {
                // ֡��ͼ
                CCTexture2D texture = CCTextureCache.sharedTextureCache().addImage("imgs/bird/bird_0" + i);

                // �������һ�������bug����������õĻ����ͻᲥ�Ų���������
                texture.Name = (uint)i;
                var frame = CCSpriteFrame.frameWithTexture(texture, new CCRect(0, 0, texture.ContentSizeInPixels.width, texture.ContentSizeInPixels.height));
                frames.Add(frame);
            }

            // �����
            CCAnimation marmotShowanimation = CCAnimation.animationWithFrames(frames, 0.1f);
            CCAnimate flyAction = CCAnimate.actionWithAnimation(marmotShowanimation, false);
            flyRepeatAction = CCRepeat.actionWithAction(flyAction, 2);
            flyRepeatAction.tag = 0;
            bird.runAction(flyRepeatAction);

            // �����������ж���һ��body��������λ�ã�����bird��֮��Ӧ
            b2BodyDef ballBodyDef = new b2BodyDef();
            ballBodyDef.type = b2BodyType.b2_dynamicBody;
            ballBodyDef.position = new b2Vec2(AppDelegate.screenSize.width / PTM_RATIO / 2, (float)(AppDelegate.screenSize.height / PTM_RATIO));
            ballBodyDef.userData = bird;
            birdBody = world.CreateBody(ballBodyDef);

            // Ϊbody������״��������һЩ��������
            b2PolygonShape shape = new b2PolygonShape();
            shape.SetAsBox(bird.contentSize.width / 2 / PTM_RATIO, bird.contentSize.height / 2 / PTM_RATIO);
            b2FixtureDef fixtureDef = new b2FixtureDef();
            fixtureDef.shape = shape;
            fixtureDef.density = 500.0f;
            fixtureDef.friction = 0.5f;
            birdBody.CreateFixture(fixtureDef);

            this.addChild(bird);
        }
开发者ID:hj458377603,项目名称:FlappyBird,代码行数:49,代码来源:GameScene.cs


示例19: AddBar

        /// <summary>
        /// ����ڵ��ϰ�
        /// </summary>
        /// <param name="interval"></param>
        private void AddBar(float interval)
        {
            int offset = new Random().Next(-160, 50);

            // upBar
            CCSprite upBar = CCSprite.spriteWithFile("imgs/bar/up_bar");
            b2BodyDef upBarBodyDef = new b2BodyDef();
            upBarBodyDef.position = new b2Vec2(AppDelegate.screenSize.width / PTM_RATIO, (AppDelegate.screenSize.height + offset + 80) / PTM_RATIO);
            upBarBodyDef.userData = upBar;

            // ��������Ӱ�죬�������ٶ�
            upBarBodyDef.type = b2BodyType.b2_kinematicBody;

            b2Body upBarBody = world.CreateBody(upBarBodyDef);

            b2PolygonShape upBarBox = new b2PolygonShape();
            b2FixtureDef boxShapeDef = new b2FixtureDef();
            boxShapeDef.shape = upBarBox;
            upBarBox.SetAsBox(upBar.contentSize.width / PTM_RATIO / 2, upBar.contentSize.height / PTM_RATIO / 2);

            upBarBody.LinearVelocity = new b2Vec2(-flySpeed, 0);
            upBarBody.CreateFixture(boxShapeDef);

            barLayer.addChild(upBar);

            if (upBars == null)
            {
                upBars = new Queue<CCSprite>();
            }

            // ���²����Ķ�����뵽������
            upBars.Enqueue(upBar);

            // downBar
            CCSprite downBar = CCSprite.spriteWithFile("imgs/bar/down_bar");
            b2BodyDef downBarBodyDef = new b2BodyDef();
            downBarBodyDef.position = new b2Vec2(AppDelegate.screenSize.width / PTM_RATIO, (downBar.contentSize.height + offset * 2 - 80) / 2 / PTM_RATIO);
            downBarBodyDef.userData = downBar;
            downBarBodyDef.type = b2BodyType.b2_kinematicBody;

            b2Body downBarBody = world.CreateBody(downBarBodyDef);

            b2PolygonShape downBarBox = new b2PolygonShape();
            b2FixtureDef shapeDef = new b2FixtureDef();
            shapeDef.shape = downBarBox;
            downBarBox.SetAsBox(downBar.contentSize.width / PTM_RATIO / 2, downBar.contentSize.height / PTM_RATIO / 2);

            downBarBody.LinearVelocity = new b2Vec2(-flySpeed, 0);
            downBarBody.CreateFixture(shapeDef);
            barLayer.addChild(downBar);
        }
开发者ID:hj458377603,项目名称:FlappyBird,代码行数:55,代码来源:GameScene.cs


示例20: LaunchBomb

        public void LaunchBomb(b2Vec2 position, b2Vec2 velocity)
        {
            if (m_bomb != null)
            {
                m_world.DestroyBody(m_bomb);
                m_bomb = null;
            }

            b2BodyDef bd = new b2BodyDef();
            bd.type = b2BodyType.b2_dynamicBody;
            bd.position = position;
            bd.bullet = true;
            m_bomb = m_world.CreateBody(bd);
            m_bomb.LinearVelocity = velocity;

            b2CircleShape circle = new b2CircleShape();
            circle.Radius = 0.3f;

            b2FixtureDef fd = new b2FixtureDef();
            fd.shape = circle;
            fd.density = 20.0f;
            fd.restitution = 0.0f;

            b2Vec2 minV = position - new b2Vec2(0.3f, 0.3f);
            b2Vec2 maxV = position + new b2Vec2(0.3f, 0.3f);

            b2AABB aabb = new b2AABB();
            aabb.LowerBound = minV;
            aabb.UpperBound = maxV;

            m_bomb.CreateFixture(fd);
        }
开发者ID:KevinHeyer,项目名称:CocosSharp,代码行数:32,代码来源:Test.cs



注:本文中的Box2D.Dynamics.b2FixtureDef类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Dynamics.b2World类代码示例发布时间:2022-05-24
下一篇:
C# Dynamics.b2BodyDef类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap