么有。这个我给你个demo,你自己看看。
1.初始化
this.Matter.Events.on(this._engine, 'collisionActive', this.onCollision);
2.碰撞检测
private onCollision(event): void
{
console.log("碰撞了..");
var home = _gamePage._mainPage._playPage;
for(var i = 0; i < event.pairs.length; i++) {
var pair = event.pairs[i];
if(!(pair.bodyA.label === 'gun' || pair.bodyB.label == "gun")) continue;
var other;
if (pair.bodyA.label === 'gun')
{
other = pair.bodyB;
}
else
{
other = pair.bodyA;
}
switch(other.label)
{
case "gameover":
{
home.onGameOver();
}
break;
case "coin":
{
home.gainCoin(1);
}
break;
case "bullet":
{
home.gainBullet(1);
}
break;
}
console.log("删除物体:", other.label);
home.Matter.World.remove(home._engine.world, other);
}
}