颈背在碰撞中移除身体

时间:2013-05-01 13:44:25

标签: collision-detection removechild nape

我有一个功能可以检测对象何时发生碰撞但是如何删除其中一个呢?

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

3 个答案:

答案 0 :(得分:1)

用Nape从模拟中移除身体的首选习语似乎是:

ball.space = null;

尽管它在内部调用了space.bodies.remove(),但它也会进行一些额外的检查。

答案 1 :(得分:0)

my answer.....

如果有人有更好的/替代方案希望听到它......

private function fruitToFloorCollision(collision:InteractionCallback):void
        {


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

答案 2 :(得分:0)

据我所知,考虑到你有两个对象水果和地板,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);
    }