开发者

How can I create a polygon body in Box2D Android?

I am new to and开发者_Python百科roidBox2D and I want to create a polygon body such as a rectangle or a triangle using Box2D in Android.

I was not getting the B2FixtureDef in my code when I was creating a body. What may be the reason for that?

But I am getting BBFixtureDef. What is the difference between B2FixtureDef and BBFixtureDef?


Here is the code for my 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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜