如何在Box2D Android中创建多边形体?

时间:2011-01-29 16:46:09

标签: android box2d

我是androidBox2D的新手,我想创建一个多边形体,如矩形或三角形 在Android中使用Box2D。

当我创建一个正文时,我的代码中没有B2FixtureDef。可能是什么原因?

但我得到了BBFixtureDefB2FixtureDefBBFixtureDef之间有什么区别?

1 个答案:

答案 0 :(得分:0)

以下是我Box2D (LibGDX box2D library)的代码:

CODE:
            protected static CCSprite _rect1 = null;
....
            _rect1 = CCSprite.sprite("NAMEOFIMAGE.png");
            _rect1.setPosition(CGPoint.make(-10, -10));
            this.addChild(_rect1);
            //Create box
            BodyDef Box1BodyDef = new BodyDef();
            Box1BodyDef.type = BodyType.DynamicBody;
            Box1BodyDef.position.set(350/PTM_RATIO, 80/PTM_RATIO);

            // The body is also added to the world.
            Body Box1Body = _world.createBody(Box1BodyDef);
            Box1Body.setUserData(_rect1);

            // Define the shape.
            PolygonShape Box1Box = new PolygonShape();


            Box1Box.setAsBox(10/PTM_RATIO, 50/PTM_RATIO);
            Box1Body.createFixture(Box1Box,1.5f);