Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android GDX Box2D Triangle Shape

I need a triangle shape definition for Box2D GDX Android. Would I just divide the width by 3 or is there a class for it? Here is code for normal rectangle:

            _rect1 = CCSprite.sprite("RectWood.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);

:) Thanks, Joe

like image 923
Jo Silter Avatar asked Feb 25 '12 22:02

Jo Silter


1 Answers

Just add 3 vertices to your Box1Box object instead of calling setAsBox().

like image 164
Aurelien Ribon Avatar answered Oct 03 '22 16:10

Aurelien Ribon