2013-05-01 95 views
0

我有一個函數可以檢測物體何時碰撞,但是如何刪除其中的一個?頸背在碰撞中刪除身體

private function fruitToFloorCollision(collision:InteractionCallback):void 
     { 
      // TODO Auto Generated method stub 

      trace('fruit hits floor'); 

     } 

當我描繪出碰撞

Cb:BEGIN:(dynamic)#11/(static)#1 : [CollisionArbiter(Polygon#2|Circle#12)[SD]<-ACCEPT] : listener: InteractionListener{BEGIN#COLLISION::@{[CbType#5] excluding []}:@{[CbType#6] excluding []}} precedence=0 

回答

0
my answer..... 

,如果一個人有一個更好的/替代想聽聽它...

private function fruitToFloorCollision(collision:InteractionCallback):void 
     { 


      var ball:Body = collision.int1 as Body; 
      removeChild(ball.userData.graphic); 
      space.bodies.remove(ball); 
     } 
1

的首選用成語從仿真中刪除身體似乎是:

ball.space = null; 

雖然它在內部調用space.bodies.remove(),但它也會執行一些額外的檢查。

0

據我所知,考慮到你有2個物體水果和地板,interactionListener按這個順序添加。

private function fruitToFloorCollision(collision:InteractionCallback):void 
    { 

     // CBTypes are added to Shapes not Bodies. So collision.int1 is a shape. 

     var fruit:Body = collision.int1.castShape.body as Body; 
     removeChild(fruit.userData.graphic); 
     space.bodies.remove(fruit); 
    }