当前位置: 首页>>代码示例>>C#>>正文


C# Body.CreateFixture方法代码示例

本文整理汇总了C#中Box2DX.Dynamics.Body.CreateFixture方法的典型用法代码示例。如果您正苦于以下问题:C# Body.CreateFixture方法的具体用法?C# Body.CreateFixture怎么用?C# Body.CreateFixture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Box2DX.Dynamics.Body的用法示例。


在下文中一共展示了Body.CreateFixture方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Projectile

        public Projectile(Player creator, float x, float y, float width, float height)
            : base(creator, 0, 0)
        {
            /* Create New Projectile Body */
            BodyDef def = new BodyDef();
            def.IsBullet = true;
            def.Position = creator.body.GetPosition() + new Vec2(x, y);
            projectile = creator.body.GetWorld().CreateBody(def);

            /* Create a fixture for the projectile */
            PolygonDef fixdef = new PolygonDef();
            fixdef.Density = 1.0f;
            fixdef.SetAsBox(width / 2, height / 2);
            fixdef.Filter.GroupIndex = creator.ID;
            fixture = projectile.CreateFixture(fixdef);
            fixture.Filter.CategoryBits = 0x0004;
            fixture.Filter.MaskBits = 0xFFFF;

            /* Made a 2nd fixture, one to observe all collisions */
            fixdef.IsSensor = true;
            fix2 = projectile.CreateFixture(fixdef);
            fix2.UserData = this;

            /* Finally, give this projectile some mass */
            projectile.SetMassFromShapes();

            /* Also, make sure we destroy the projectile when it is time */
            this.OnDestroy += Cleanup;
        }
开发者ID:CloneDeath,项目名称:PokemonSmash,代码行数:29,代码来源:Projectile.cs

示例2: Breakable

        public Breakable()
        {
            // Ground body
            {
                BodyDef bd = new BodyDef();
                Body ground = _world.CreateBody(bd);

                PolygonShape shape = new PolygonShape();
                shape.SetAsEdge(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f));
                ground.CreateFixture(shape, 0);
            }

            // Breakable dynamic body
            {
                BodyDef bd = new BodyDef();
                bd.Position.Set(0.0f, 40.0f);
                bd.Angle = 0.25f * Box2DX.Common.Settings.PI;
                _body1 = _world.CreateBody(bd);

                _shape1.SetAsBox(0.5f, 0.5f, new Vec2(-0.5f, 0.0f), 0.0f);
                _piece1 = _body1.CreateFixture(_shape1, 1.0f);

                _shape2.SetAsBox(0.5f, 0.5f, new Vec2(0.5f, 0.0f), 0.0f);
                _piece2 = _body1.CreateFixture(_shape2, 1.0f);
            }

            _break = false;
            _broke = false;
        }
开发者ID:rbrother,项目名称:seikkailulaakso,代码行数:29,代码来源:Breakable.cs

示例3: TheoJansen

        public TheoJansen()
        {
            _offset.Set(0.0f, 8.0f);
            _motorSpeed = 2.0f;
            _motorOn = true;
            Vec2 pivot = new Vec2(0.0f, 0.8f);

            // Ground
            {
                BodyDef bd = new BodyDef();
                Body ground = _world.CreateBody(bd);

                PolygonShape shape = new PolygonShape();
                shape.SetAsEdge(new Vec2(-50.0f, 0.0f), new Vec2(50.0f, 0.0f));
                ground.CreateFixture(shape, 0);

                shape.SetAsEdge(new Vec2(-50.0f, 0.0f), new Vec2(-50.0f, 10.0f));
                ground.CreateFixture(shape, 0);

                shape.SetAsEdge(new Vec2(50.0f, 0.0f), new Vec2(50.0f, 10.0f));
                ground.CreateFixture(shape, 0);
            }

            // Balls
            for (int i = 0; i < 40; ++i)
            {
                CircleShape shape = new CircleShape();
                shape._radius = 0.25f;

                BodyDef bd = new BodyDef();
                bd.Position.Set(-40.0f + 2.0f * i, 0.5f);

                Body body = _world.CreateBody(bd);
                body.CreateFixture(shape, 1.0f);
            }

            // Chassis
            {
                PolygonShape shape = new PolygonShape();
                shape.SetAsBox(2.5f, 1.0f);

                FixtureDef sd = new FixtureDef();
                sd.Density = 1.0f;
                sd.Shape = shape;
                sd.Filter.GroupIndex = -1;
                BodyDef bd = new BodyDef();
                bd.Position = pivot + _offset;
                _chassis = _world.CreateBody(bd);
                _chassis.CreateFixture(sd);
            }

            {
                CircleShape shape = new CircleShape();
                shape._radius = 1.6f;

                FixtureDef sd = new FixtureDef();
                sd.Density = 1.0f;
                sd.Shape = shape;
                sd.Filter.GroupIndex = -1;
                BodyDef bd = new BodyDef();
                bd.Position = pivot + _offset;
                _wheel = _world.CreateBody(bd);
                _wheel.CreateFixture(sd);
            }

            {
                RevoluteJointDef jd = new RevoluteJointDef();
                jd.Initialize(_wheel, _chassis, pivot + _offset);
                jd.CollideConnected = false;
                jd.MotorSpeed = _motorSpeed;
                jd.MaxMotorTorque = 400.0f;
                jd.EnableMotor = _motorOn;
                _motorJoint = (RevoluteJoint)_world.CreateJoint(jd);
            }

            Vec2 wheelAnchor;

            wheelAnchor = pivot + new Vec2(0.0f, -0.8f);

            CreateLeg(-1.0f, wheelAnchor);
            CreateLeg(1.0f, wheelAnchor);

            _wheel.SetTransform(_wheel.GetPosition(), 120.0f * Box2DX.Common.Settings.PI / 180.0f);
            CreateLeg(-1.0f, wheelAnchor);
            CreateLeg(1.0f, wheelAnchor);

            _wheel.SetTransform(_wheel.GetPosition(), -120.0f * Box2DX.Common.Settings.PI / 180.0f);
            CreateLeg(-1.0f, wheelAnchor);
            CreateLeg(1.0f, wheelAnchor);
        }
开发者ID:rbrother,项目名称:seikkailulaakso,代码行数:90,代码来源:TheoJansen.cs

示例4: AddBoundaryBlock

        private void AddBoundaryBlock(Body groundBody, float x, float y, float width, float height)
        {
            // Define the ground box shape.
            PolygonDef groundShapeDef = new PolygonDef();
            groundShapeDef.SetAsBox(width/2, height/2, new Vec2(x, y), 0);

            // Add the ground shape to the ground body.
            Fixture fix = groundBody.CreateFixture(groundShapeDef);

            fix.UserData = this;
            fix.Filter.CategoryBits = 0x0001;
        }
开发者ID:CloneDeath,项目名称:PokemonSmash,代码行数:12,代码来源:BattleArena.cs

示例5: Keyboard

		public override void Keyboard(System.Windows.Forms.Keys key)
		{
			switch (key)
			{
				case System.Windows.Forms.Keys.B:
					if (_bullet != null)
					{
						_world.DestroyBody(_bullet);
						_bullet = null;
					}
					{
						CircleDef sd = new CircleDef();
						sd.Density = 20.0f;
						sd.Radius = 0.25f;
						sd.Restitution = 0.05f;

						BodyDef bd = new BodyDef();
						bd.IsBullet = true;
						bd.Position.Set(-31.0f, 5.0f);

						_bullet = _world.CreateBody(bd);
						_bullet.CreateFixture(sd);
						_bullet.SetMassFromShapes();

						_bullet.SetLinearVelocity(new Vec2(400.0f, 0.0f));
					}
					break;
			}
		}
开发者ID:ajmaya,项目名称:box2dx,代码行数:29,代码来源:VerticalStack.cs

示例6: InitPhysics

        private void InitPhysics(BattleArena arena)
        {
            // Define the dynamic body. We set its position and call the body factory.
            BodyDef bodyDef = new BodyDef();
            bodyDef.Position.Set(0.0f, 4.0f);
            body = arena.world.CreateBody(bodyDef);

            // Define another box shape for our dynamic body.
            PolygonDef shapeDef = new PolygonDef();
            shapeDef.SetAsBox(Pokemon.Width / 2, Pokemon.Height / 2);

            // Set the box density to be non-zero, so it will be dynamic.
            shapeDef.Density = 1.0f;

            // Override the default friction.
            //shapeDef.Friction = 2f;

            // Add the shape to the body.
            Fixture fix = body.CreateFixture(shapeDef);
            fix.Density = 1;
            fix.Friction = 0.3f;
            fix.Restitution = 0.1f;
            fix.UserData = this;
            fix.Filter.GroupIndex = this.ID;
            fix.Filter.CategoryBits = 0x0002;
            if (Pokemon.Types.Contains(PokemonType.Ghost)){
                fix.Filter.MaskBits = 0xFFFF - 0x0002;
            } else {
                fix.Filter.MaskBits = 0xFFFF;
            }

            // Now tell the dynamic body to compute it's mass properties base
            // on its shape.
            var mass = body.GetMassData();
            mass.Mass = Pokemon.Weight;
            body.SetMass(mass);

            body.SetFixedRotation(true);
        }
开发者ID:CloneDeath,项目名称:PokemonSmash,代码行数:39,代码来源:Player.cs

示例7: LaunchBomb

        public void LaunchBomb(Vec2 position, Vec2 velocity)
        {
            if (_bomb != null)
            {
                _world.DestroyBody(_bomb);
                _bomb = null;
            }

            BodyDef bd = new BodyDef();
            bd.AllowSleep = true;
            bd.Position = position;

            bd.IsBullet = true;
            _bomb = _world.CreateBody(bd);
            _bomb.SetLinearVelocity(velocity);

            CircleShape circle = new CircleShape();
            circle._radius = 0.3f;

            FixtureDef fd = new FixtureDef();
            fd.Shape = circle;
            fd.Density = 20.0f;
            fd.Restitution = 0.1f;

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

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

            _bomb.CreateFixture(fd);
        }
开发者ID:rbrother,项目名称:seikkailulaakso,代码行数:33,代码来源:Test.cs

示例8: ApplyForce

        public ApplyForce()
        {
            _world.Gravity = new Vec2(0.0f, 0.0f);

            const float k_restitution = 0.4f;

            {
                BodyDef bd = new BodyDef();
                bd.Position.Set(0.0f, 20.0f);
                Body ground = _world.CreateBody(bd);

                PolygonShape shape = new PolygonShape();

                FixtureDef sd = new FixtureDef();
                sd.Shape = shape;
                sd.Density = 0.0f;
                sd.Restitution = k_restitution;

                // Left vertical
                shape.SetAsEdge(new Vec2(-20.0f, -20.0f), new Vec2(-20.0f, 20.0f));
                ground.CreateFixture(sd);

                // Right vertical
                shape.SetAsEdge(new Vec2(20.0f, -20.0f), new Vec2(20.0f, 20.0f));
                ground.CreateFixture(sd);

                // Top horizontal
                shape.SetAsEdge(new Vec2(-20.0f, 20.0f), new Vec2(20.0f, 20.0f));
                ground.CreateFixture(sd);

                // Bottom horizontal
                shape.SetAsEdge(new Vec2(-20.0f, -20.0f), new Vec2(20.0f, -20.0f));
                ground.CreateFixture(sd);
            }

            {
                Transform xf1 = new Transform();
                xf1.R.Set(0.3524f * Box2DX.Common.Settings.PI);
                xf1.Position = Math.Mul(xf1.R, new Vec2(1.0f, 0.0f));

                Vec2[] vertices = new Vec2[3];
                vertices[0] = Math.Mul(xf1, new Vec2(-1.0f, 0.0f));
                vertices[1] = Math.Mul(xf1, new Vec2(1.0f, 0.0f));
                vertices[2] = Math.Mul(xf1, new Vec2(0.0f, 0.5f));

                PolygonShape poly1 = new PolygonShape();
                poly1.Set(vertices, 3);

                FixtureDef sd1 = new FixtureDef();
                sd1.Shape = poly1;
                sd1.Density = 2.0f;

                Transform xf2 = new Transform();
                xf2.R.Set(-0.3524f * Box2DX.Common.Settings.PI);
                xf2.Position = Math.Mul(xf2.R, new Vec2(-1.0f, 0.0f));

                vertices[0] = Math.Mul(xf2, new Vec2(-1.0f, 0.0f));
                vertices[1] = Math.Mul(xf2, new Vec2(1.0f, 0.0f));
                vertices[2] = Math.Mul(xf2, new Vec2(0.0f, 0.5f));

                PolygonShape poly2 = new PolygonShape();
                poly2.Set(vertices, 3);

                FixtureDef sd2 = new FixtureDef();
                sd2.Shape = poly2;
                sd2.Density = 2.0f;

                BodyDef bd = new BodyDef();
                bd.AngularDamping = 2.0f;
                bd.LinearDamping = 0.1f;

                bd.Position.Set(0.0f, 2.0f);
                bd.Angle = Box2DX.Common.Settings.PI;
                _body = _world.CreateBody(bd);
                _body.CreateFixture(sd1);
                _body.CreateFixture(sd2);
            }
        }
开发者ID:rbrother,项目名称:seikkailulaakso,代码行数:78,代码来源:ApplyForce.cs


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