碰撞检测系统
1: creator有碰撞检测系统 +物理碰撞系统,这个是两个独立的模块;
2: 给creator的游戏世界中的物体来进行分组,指定节点的分组与分组的碰撞矩阵;
3: 代码中获取节点的分组和分组索引: group与groupIndex;
4: 为每个节点添加碰撞检测区域-->碰撞器(物体形状), 编辑碰撞区域;
5: 代码开启碰撞检测系统(默认是关闭碰撞检测),开启和关闭碰撞检测的调试:
var manager = cc.director.getCollisionManager(); //
manager.enabled = true; // 开启碰撞
manager.enabledDebugDraw = true; // 允许绘制碰撞的区域
6: 碰撞检测函数响应,发生碰撞检测的节点,会调用这个节点上所有组件的统一的三个接口:
onCollisionEnter: function (other, self) // 开始
onCollisionStay: function (other, self) // 持续
onCollisionExit: function (other, self) // 结束
其中other是与这个节点碰撞的节点的碰撞器组件
其中self是自身节点的碰撞器组件
是碰撞器组件,不是节点-->碰撞器组件.node
======================================================
开启碰撞
cc.Class({
extends: cc.Component,
properties: {
// foo: {
// default: null, // The default value will be used only when the component attaching
// to a node for the first time
// url: cc.Texture2D, // optional, default is typeof default
// serializable: true, // optional,