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


C# b2PolygonShape.SetAsBox方法代码示例

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


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

示例1: 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

示例2: CreatePhysicsShape

 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 public override b2Shape CreatePhysicsShape()
 {
     var shape = new b2PolygonShape();
     shape.SetAsBox(PhysicWidth / 2f, PhysicHeight / 2f);
     GroundSprite.DrawRect(new CCRect(0, 0,  Width, Height), CCColor4B.Black);
     return shape;
 }
开发者ID:hussein-aitlahcen,项目名称:heroesrpg,代码行数:11,代码来源:Ground.cs

示例3: ContinuousTest

        public ContinuousTest()
        {
            {
                b2BodyDef bd  = new b2BodyDef();
                bd.position.Set(0.0f, 0.0f);
                b2Body body = m_world.CreateBody(bd);

                b2EdgeShape edge = new b2EdgeShape();

                edge.Set(new b2Vec2(-10.0f, 0.0f), new b2Vec2(10.0f, 0.0f));
                body.CreateFixture(edge, 0.0f);

                b2PolygonShape shape = new b2PolygonShape();
                shape.SetAsBox(0.2f, 1.0f, new b2Vec2(0.5f, 1.0f), 0.0f);
                body.CreateFixture(shape, 0.0f);
            }

#if true
            {
                b2BodyDef bd  = new b2BodyDef();
                bd.type = b2BodyType.b2_dynamicBody;
                bd.position.Set(0.0f, 20.0f);
                //bd.angle = 0.1f;

                b2PolygonShape shape = new b2PolygonShape();
                shape.SetAsBox(2.0f, 0.1f);

                m_body = m_world.CreateBody(bd);
                m_body.CreateFixture(shape, 1.0f);

                m_angularVelocity = Rand.RandomFloat(-50.0f, 50.0f);
                //m_angularVelocity = 46.661274f;
                m_body.LinearVelocity = new b2Vec2(0.0f, -100.0f);
                m_body.AngularVelocity = m_angularVelocity;
            }
#else
        {
            b2BodyDef bd  = new b2BodyDef();
            bd.type = b2BodyType.b2_dynamicBody;
            bd.position.Set(0.0f, 2.0f);
            b2Body body = m_world.CreateBody(bd);

            b2CircleShape shape = new b2CircleShape();
            shape.Position = b2Vec2.Zero;
            shape.Radius = 0.5f;
            body.CreateFixture(shape, 1.0f);

            bd.bullet = true;
            bd.position.Set(0.0f, 10.0f);
            body = m_world.CreateBody(bd);
            body.CreateFixture(shape, 1.0f);
            body.LinearVelocity = new b2Vec2(0.0f, -100.0f);
        }
#endif
        }
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:55,代码来源:ContinuousTest.cs

示例4: BulletTest

        public BulletTest()
        {
            {
                b2BodyDef bd  = new b2BodyDef();
                bd.position.Set(0.0f, 0.0f);
                b2Body body = m_world.CreateBody(bd);

                b2EdgeShape edge = new b2EdgeShape();

                edge.Set(new b2Vec2(-10.0f, 0.0f), new b2Vec2(10.0f, 0.0f));
                body.CreateFixture(edge, 0.0f);

                b2PolygonShape shape = new b2PolygonShape();
                shape.SetAsBox(0.2f, 1.0f, new b2Vec2(0.5f, 1.0f), 0.0f);
                body.CreateFixture(shape, 0.0f);
            }

            {
                b2BodyDef bd  = new b2BodyDef();
                bd.type = b2BodyType.b2_dynamicBody;
                bd.position.Set(0.0f, 4.0f);

                b2PolygonShape box = new b2PolygonShape();
                box.SetAsBox(2.0f, 0.1f);

                m_body = m_world.CreateBody(bd);
                m_body.CreateFixture(box, 1.0f);

                box.SetAsBox(0.25f, 0.25f);

                //m_x = RandomFloat(-1.0f, 1.0f);
                m_x = 0.20352793f;
                bd.position.Set(m_x, 10.0f);
                bd.bullet = true;

                m_bullet = m_world.CreateBody(bd);
                m_bullet.CreateFixture(box, 100.0f);

                m_bullet.LinearVelocity = new b2Vec2(0.0f, -50.0f);
            }
        }
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:41,代码来源:BulletTest.cs

示例5: Pulleys

        public Pulleys()
        {
            float y = 16.0f;
            float L = 12.0f;
            float a = 1.0f;
            float b = 2.0f;

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

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

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

                circle.Position = new b2Vec2(-10.0f, y + b + L);
                ground.CreateFixture(circle, 0.0f);

                circle.Position = new b2Vec2(10.0f, y + b + L);
                ground.CreateFixture(circle, 0.0f);
            }

            {

                b2PolygonShape shape = new b2PolygonShape();
                shape.SetAsBox(a, b);

                b2BodyDef bd  = new b2BodyDef();
                bd.type = b2BodyType.b2_dynamicBody;

                //bd.fixedRotation = true;
                bd.position.Set(-10.0f, y);
                b2Body body1 = m_world.CreateBody(bd);
                body1.CreateFixture(shape, 5.0f);

                bd.position.Set(10.0f, y);
                b2Body body2 = m_world.CreateBody(bd);
                body2.CreateFixture(shape, 5.0f);

                b2PulleyJointDef pulleyDef = new b2PulleyJointDef();
                b2Vec2 anchor1 = new b2Vec2(-10.0f, y + b);
                b2Vec2 anchor2 = new b2Vec2(10.0f, y + b);
                b2Vec2 groundAnchor1 = new b2Vec2(-10.0f, y + b + L);
                b2Vec2 groundAnchor2 = new b2Vec2(10.0f, y + b + L);
                pulleyDef.Initialize(body1, body2, groundAnchor1, groundAnchor2, anchor1, anchor2, 1.5f);

                m_joint1 = (b2PulleyJoint) m_world.CreateJoint(pulleyDef);
            }
        }
开发者ID:Karunp,项目名称:cocos2d-xna,代码行数:53,代码来源:Pulleys.cs

示例6: Tumbler

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

            {
                b2BodyDef bd  = new b2BodyDef();
                bd.type = b2BodyType.b2_dynamicBody;
                bd.allowSleep = false;
                bd.position.Set(0.0f, 10.0f);
                b2Body body = m_world.CreateBody(bd);

                b2PolygonShape shape = new b2PolygonShape();
                shape.SetAsBox(0.5f, 10.0f, new b2Vec2(10.0f, 0.0f), 0.0f);
                body.CreateFixture(shape, 5.0f);
                shape.SetAsBox(0.5f, 10.0f, new b2Vec2(-10.0f, 0.0f), 0.0f);
                body.CreateFixture(shape, 5.0f);
                shape.SetAsBox(10.0f, 0.5f, new b2Vec2(0.0f, 10.0f), 0.0f);
                body.CreateFixture(shape, 5.0f);
                shape.SetAsBox(10.0f, 0.5f, new b2Vec2(0.0f, -10.0f), 0.0f);
                body.CreateFixture(shape, 5.0f);

                b2RevoluteJointDef jd = new b2RevoluteJointDef();
                jd.BodyA = ground;
                jd.BodyB = body;
                jd.localAnchorA.Set(0.0f, 10.0f);
                jd.localAnchorB.Set(0.0f, 0.0f);
                jd.referenceAngle = 0.0f;
                jd.motorSpeed = 0.05f * b2Settings.b2_pi;
                jd.maxMotorTorque = 1e8f;
                jd.enableMotor = true;
                m_joint = (b2RevoluteJoint) m_world.CreateJoint(jd);
            }

            m_count = 0;
        }
开发者ID:Karunp,项目名称:cocos2d-xna,代码行数:39,代码来源:Tumbler.cs

示例7: 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

示例8: Step

        public override void Step(Settings settings)
        {
            base.Step(settings);

            if (m_count < e_count)
            {
                b2BodyDef bd  = new b2BodyDef();
                bd.type = b2BodyType.b2_dynamicBody;
                bd.position.Set(0.0f, 10.0f);
                b2Body body = m_world.CreateBody(bd);

                b2PolygonShape shape = new b2PolygonShape();
                shape.SetAsBox(0.125f, 0.125f);
                body.CreateFixture(shape, 1.0f);

                ++m_count;
            }
        }
开发者ID:Karunp,项目名称:cocos2d-xna,代码行数:18,代码来源:Tumbler.cs

示例9: Prismatic

        public Prismatic()
        {
            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(2.0f, 0.5f);

                b2BodyDef bd  = new b2BodyDef();
                bd.type = b2BodyType.b2_dynamicBody;
                bd.position.Set(-10.0f, 10.0f);
                bd.angle = 0.5f * b2Settings.b2_pi;
                bd.allowSleep = false;
                b2Body body = m_world.CreateBody(bd);
                body.CreateFixture(shape, 5.0f);

                b2PrismaticJointDef pjd = new b2PrismaticJointDef();

                // Bouncy limit
                b2Vec2 axis = new b2Vec2(2.0f, 1.0f);
                axis.Normalize();
                pjd.Initialize(ground, body, new b2Vec2(0.0f, 0.0f), axis);

                // Non-bouncy limit
                //pjd.Initialize(ground, body, b2Vec2(-10.0f, 10.0f), b2Vec2(1.0f, 0.0f));

                pjd.motorSpeed = 10.0f;
                pjd.maxMotorForce = 10000.0f;
                pjd.enableMotor = true;
                pjd.lowerTranslation = 0.0f;
                pjd.upperTranslation = 20.0f;
                pjd.enableLimit = true;

                m_joint = (b2PrismaticJoint) m_world.CreateJoint(pjd);
            }
        }
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:44,代码来源:Prismatic.cs

示例10: 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

示例11: OneSidedPlatform

        public OneSidedPlatform()
        {
            // Ground
            {
                b2BodyDef bd  = new b2BodyDef();
                b2Body ground = m_world.CreateBody(bd);

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

            // Platform
            {
                b2BodyDef bd  = new b2BodyDef();
                bd.position.Set(0.0f, 10.0f);
                b2Body body = m_world.CreateBody(bd);

                b2PolygonShape shape = new b2PolygonShape();
                shape.SetAsBox(3.0f, 0.5f);
                m_platform = body.CreateFixture(shape, 0.0f);

                m_bottom = 10.0f - 0.5f;
                m_top = 10.0f + 0.5f;
            }

            // Actor
            {
                b2BodyDef bd  = new b2BodyDef();
                bd.type = b2BodyType.b2_dynamicBody;
                bd.position.Set(0.0f, 12.0f);
                b2Body body = m_world.CreateBody(bd);

                m_radius = 0.5f;
                b2CircleShape shape = new b2CircleShape();
                shape.Radius = m_radius;
                m_character = body.CreateFixture(shape, 20.0f);

                body.LinearVelocity = new b2Vec2(0.0f, -50.0f);

                m_state = State.e_unknown;
            }
        }
开发者ID:Karunp,项目名称:cocos2d-xna,代码行数:43,代码来源:OneSidedPlatform.cs

示例12: 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

示例13: Pyramid

        public Pyramid()
        {
            {
                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);
            }

            {
                float a = 0.5f;
                b2PolygonShape shape = new b2PolygonShape();
                shape.SetAsBox(a, a);

                b2Vec2 x = new b2Vec2(-7.0f, 0.75f);
                b2Vec2 y;
                b2Vec2 deltaX = new b2Vec2(0.5625f, 1.25f);
                b2Vec2 deltaY = new b2Vec2(1.125f, 0.0f);

                for (int i = 0; i < e_count; ++i)
                {
                    y = x;

                    for (int j = i; j < e_count; ++j)
                    {
                        b2BodyDef bd  = new b2BodyDef();
                        bd.type = b2BodyType.b2_dynamicBody;
                        bd.position = y;
                        b2Body body = m_world.CreateBody(bd);
                        body.CreateFixture(shape, 5.0f);

                        y += deltaY;
                    }

                    x += deltaX;
                }
            }
        }
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:40,代码来源:Pyramid.cs

示例14: 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

示例15: ShapeEditing

        public ShapeEditing()
        {
            {
                b2BodyDef bd1  = new b2BodyDef();
                b2Body ground = m_world.CreateBody(bd1);

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

            b2BodyDef bd  = new b2BodyDef();
            bd.type = b2BodyType.b2_dynamicBody;
            bd.position.Set(0.0f, 10.0f);
            m_body = m_world.CreateBody(bd);

            b2PolygonShape shape = new b2PolygonShape();
            shape.SetAsBox(4.0f, 4.0f, new b2Vec2(0.0f, 0.0f), 0.0f);
            m_fixture1 = m_body.CreateFixture(shape, 10.0f);

            m_fixture2 = null;

            m_sensor = false;
        }
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:24,代码来源:ShapeEditing.cs


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