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
4

3 回答 3

1

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

ball.space = null;

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

于 2014-02-02T22:41:42.263 回答
0

据我所知,考虑到您有 2 个 Objects 水果和 floor,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);
    }
于 2014-06-02T05:46:23.997 回答
0
my answer.....

如果有人有更好的/替代的想听听...

private function fruitToFloorCollision(collision:InteractionCallback):void
        {


            var ball:Body = collision.int1 as Body;
            removeChild(ball.userData.graphic);
            space.bodies.remove(ball);
        }
于 2013-05-01T14:02:28.417 回答