CollisionManager 类型
模块: cc
一个简单的碰撞组件管理类,用于处理节点之间的碰撞组件是否产生了碰撞,并调用相应回调函数。
示例
// Get the collision manager. 获取碰撞管理器
let manager = cc.director.getCollisionManager();
// Enabled the colider manager. 启用检测
manager.enabled = true;
// Enabled draw collider 绘制碰撞检测
manager.enabledDebugDraw = true;
// Enabled draw collider bounding box 绘制碰撞的盒子
manager.enabledDrawBoundingBox = true;
//如果不用回调函数那么就是
/*
onCollisionEnter(other,self){
}
*/
// Collision callback
onCollisionEnter: function (other, self) {
this.node.color = cc.Color.RED;
this.touchingNumber ++;
// let world = self.world;
// let aabb = world.aabb;
// let preAabb = world.preAabb;
// let m = world.matrix;
// for circle collider
// let r = world.radius;
// let p = world.position;
// for box collider and polygon collider
// let ps = world.points;
},
onCollisionStay: function (other, self) {
console.log('on collision stay');
},
onCollisionExit: function (other, self) {
this.touchingNumber --;
if (this.touchingNumber === 0) {
this.node.color = cc.Color.WHITE;
}
}
这篇博客介绍了如何利用cc模块中的CollisionManager类来处理游戏或应用中的节点碰撞检测。通过启用碰撞管理器,设置绘制选项,以及定义不同的碰撞回调函数(onCollisionEnter、onCollisionStay和onCollisionExit),可以实现节点间的碰撞交互,如颜色变化和触摸计数。示例代码展示了如何设置和使用这些功能。
886

被折叠的 条评论
为什么被折叠?



