使用时需要开启碰撞系统
cc.director.getCollisionManager().enabled = true;
(但不需要像物理系统那样规定必须要求在onLoad()中开启,只要在发生碰撞前开启就可以)
物理系统管理器开启需在onLoad(){}里:
onLoad(){
cc.director.getPhysicsManager().enabled = true;
}
碰撞系统回调函数
- 碰撞产生时 onCollisionEnter: function (other, self)
- 碰撞保持时 onCollisionStay: function (other, self)
- 碰撞结束时onCollisionExit: function (other, self)
other指发生碰撞的另一个组件,self指发生碰撞的自身组件
other.node就将节点指向发生碰撞的另一个组件上去了
eg:other.node.name指另一个组件的名称
可以使用console.log(other.node)打印一下该节点的属性,根据属性自取所需