2011-01-29 57 views
1

我是androidBox2D的新手,我想在Android中使用Box2D創建多邊形物體,例如矩形或三角形 。如何在Box2D Android中創建多邊形主體?

當我創建一個body時,我沒有在我的代碼中獲得B2FixtureDef。這可能是什麼原因?

但我得到BBFixtureDefB2FixtureDefBBFixtureDef有什麼區別?

回答

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