2012-02-25 8 views
5

J'ai besoin d'une définition de forme de triangle pour Box2D GDX Android. Est-ce que je diviserais juste la largeur par 3 ou est-ce qu'il y a une classe pour cela? le code est ici pour rectangle normal:Android GDX Box2D Triangle Shape

  _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); 

:) Merci, Joe

Répondre

3

Il suffit d'ajouter 3 sommets à votre objet Box1Box au lieu d'appeler setAsBox().

+0

désolé, je suis vraiment (comme un vrai débutant) un débutant à ce genre de choses. Est-ce que quelqu'un pourrait savoir comment ajouter 3 verticies? :) –

+1

Voir la section 4.4 du manuel, l'extrait de code définit comment créer un triangle. http://www.box2d.org/manual.html –

+0

ok ... merci! Je vais juste comprendre comment porter sur libgdx. :) thankyouthankyou! –