Skip to content

如何检测与当前刚体碰撞的所有刚体

Tangram edited this page May 6, 2015 · 1 revision

碰撞事件中,参数body是碰撞到的刚体。body.element是碰撞到的组件。但有时需要检测与当前刚体碰撞的所有刚体。这时可以通过this.body.GetContactList来获取与当前刚体碰撞的所有刚体。

示例:

var contactList = this.body.GetContactList();
var elements = [];
for(var p = contactList; p; p = p.next) {
    elements.push(p.other.element);
}

for(var i = 0; i < elements.length; i++) {
    console.log("contact with i=" + i + ":", elements[i].name);    
}

Clone this wiki locally