2013-09-25 2 views
0

starling + as3을 사용하여 모바일 앱의 무대 벽과 상자를 만듭니다.Starling + Box2d - 정밀하지 않은 충돌

좋아, 내가 응용 프로그램을 테스트 할 때, 이제 상자 폭포하지만 가있는 것처럼, 벽과 일치하지 않는 오프셋 :

https://www.dropbox.com/s/hd4ehnfthh0ucfm/box.png

다음

내가 상자를 생성하는 방법입니다 (벽과 상자).

오프셋이 숨겨져있는 것처럼 보입니다. 어떻게 생각하십니까?

public function createBox(x:Number, y:Number, width:Number, height:Number, rotation:Number = 0, bodyType:uint = 0):void { 

      /// Vars used to create bodies 
      var body:b2Body; 
      var boxShape:b2PolygonShape; 
      var circleShape:b2CircleShape; 

       var fixtureDef:b2FixtureDef = new b2FixtureDef(); 
      fixtureDef.shape = boxShape; 
      fixtureDef.friction = 0.3; 
      // static bodies require zero density 
      fixtureDef.density = 0; 

      var quad:Quad; 

       bodyDef = new b2BodyDef();    
       bodyDef.type = bodyType; 
       bodyDef.position.x = x/WORLD_SCALE; 
       bodyDef.position.y = y/WORLD_SCALE; 

       // Box 
       boxShape = new b2PolygonShape(); 
       boxShape.SetAsBox(width/WORLD_SCALE, height/WORLD_SCALE); 
       fixtureDef.shape = boxShape; 
       fixtureDef.density = 0; 
       fixtureDef.friction = 0.5; 
       fixtureDef.restitution = 0.2; 

       // create the quads 
       quad = new Quad(width, height, Math.random() * 0xFFFFFF); 

       quad.pivotX = 0; 
       quad.pivotY = 0; 


       // this is the key line, we pass as a userData the starling.display.Quad 
       bodyDef.userData = quad; 

       // 
       body = m_world.CreateBody(bodyDef); 
       body.CreateFixture(fixtureDef); 

       body.SetAngle(rotation * (Math.PI/180)); 

       _clipPhysique.addChild(bodyDef.userData); 

     } 

답변

0

SetAsBox 메서드는 매개 변수로 반 너비와 반쪽 높이를 사용합니다. 귀하의 그래픽이 box2d 본문과 일치하지 않는다고 생각합니다. 따라서 그래픽을 두 배로 만들거나 SetAsBox 매개 변수에 0.5를 곱해야합니다. 또한 본체 피벗이 중앙에 있으므로 피벗 위치에 따라 동영상 클립을 적절히 오프셋하십시오.

box2d에는 여러분의 몸을 개략적으로 볼 수있는 debugrenderer가 있습니다.

+0

그래, 나도 그 얘기를 들었다. setasbox는 돌보는 방법이다. – mirzahat