2011-04-12 3 views
0

동적 바디 사이의 연결을 듣고 있습니다. 그러나 동적 인 신체와 정적 인 신체 사이의 접촉을들을 수 없습니다.box2d, 정적 바디와 동적 바디 간의 충돌을 감지하는 방법

이 metod를 사용하여 b2contactListener 클래스에서 충돌 감지를 처리 ​​할 수 ​​있습니다.

public override function BeginContact(contact:b2Contact):void { 
     // getting the fixtures that collided 
     var fixtureA:b2Fixture=contact.GetFixtureA(); 
     var fixtureB:b2Fixture=contact.GetFixtureB(); 
     // if the fixture is a sensor, mark the parent body to be removed 

     if(fixtureB.GetBody().getUniqueBodyName() == "towerBody"){ 
      //Towerbody is static body 
        trace("BINGOOOOOO"); 
        } 

     if (fixtureA.GetBody().getUniqueBodyName() == "bomb"){ 
      // Bomb is dynamic body 
     // main.gamePhysics.destroyBodyWhenCollide(fixtureA.GetBody()); 

      var spr:Sprite = fixtureA.GetBody().GetUserData(); 
      spr.alpha = 0; 
      fixtureA.GetBody().collisionDetected = true;    

     } 

Plz은

답변

2

그것은 정적 몸이 fixtureB 될 것 유효한 가정이 아니다 ... 나 좀 도와 ... 그것은 fixtureA 수 있습니다. 작동 Thnks

내가 문제를 해결 ... 이것을 테스트

public override function BeginContact(contact:b2Contact):void { 
    // getting the fixtures that collided 
    var fixtureA:b2Fixture=contact.GetFixtureA(); 
    var fixtureB:b2Fixture=contact.GetFixtureB(); 
    // if the fixture is a sensor, mark the parent body to be removed 

    if(fixtureA.GetBody().getUniqueBodyName() == "towerBody"){ 
     //Towerbody is static body 
       trace("BINGOOOOOO - A"); 
       } 

    if(fixtureB.GetBody().getUniqueBodyName() == "towerBody"){ 
     //Towerbody is static body 
       trace("BINGOOOOOO - B"); 
       } 


    if (fixtureA.GetBody().getUniqueBodyName() == "bomb"){ 
     // Bomb is dynamic body 
    // main.gamePhysics.destroyBodyWhenCollide(fixtureA.GetBody()); 

     var spr:Sprite = fixtureA.GetBody().GetUserData(); 
     spr.alpha = 0; 
     fixtureA.GetBody().collisionDetected = true;    

    } 
+0

시도 – cagryInside

관련 문제