cocos这个刚体AllowSleep睡眠属性真的服了,cocos的坑是真多啊

这个属性说的是:如果此刚体永远都不应该进入睡眠,那么设置这个属性为 False。需要注意这将使 CPU 占用率提高,文档地址:Cocos Creator API

休眠:意思应该就是只展示ui效果,没有碰撞检测了,我的老天,cocos的人怎么想的,我为什么要使用刚体你不知道吗?我就是需要碰撞检测啊,你现在到好,直接给我睡眠,还是默认的,我怎么说搞了那么久,只有子弹发射出来的一下有碰撞,后面就没有了..........真的不至于默认给true啊,应该默认给false,等别人真的需要只检测一下的时候,再来设置为ture啊

还有这个碰撞回掉......我肯定是想使用碰撞的,大部分情况都是要回掉的吧,结果你到好,又给了默认false........需要勾选为true才有回掉函数:

注册回调函数

注册一个碰撞回调函数有两种方式,一种是通过指定的 collider 注册;另一种是通过 2D 物理系统注册一个全局的回调函数。

注意 :Builtin 2D 物理模块只会发送 BEGIN_CONTACTEND_CONTACT 回调消息。

javascript 复制代码
@ccclass('TestContactCallBack')
export class TestContactCallBack extends Component {
    start () {
        // 注册单个碰撞体的回调函数
        let collider = this.getComponent(Collider2D);
        if (collider) {
            collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
            collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
        }

        // 注册全局碰撞回调函数
        if (PhysicsSystem2D.instance) {
            PhysicsSystem2D.instance.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
            PhysicsSystem2D.instance.on(Contact2DType.END_CONTACT, this.onEndContact, this);
        }
    }
    onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
        // 只在两个碰撞体开始接触时被调用一次
        console.log('onBeginContact');
    }
    onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
        // 只在两个碰撞体结束接触时被调用一次
        console.log('onEndContact');
    }
    onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
        // 每次将要处理碰撞体接触逻辑时被调用
        console.log('onPreSolve');
    }
    onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
        // 每次处理完碰撞体接触逻辑时被调用
        console.log('onPostSolve');
    }
}
相关推荐
万少5 小时前
HarmonyOS 开发必会 5 种 Builder 详解
前端·harmonyos
橙序员小站7 小时前
Agent Skill 是什么?一文讲透 Agent Skill 的设计与实现
前端·后端
炫饭第一名9 小时前
速通Canvas指北🦮——基础入门篇
前端·javascript·程序员
王晓枫10 小时前
flutter接入三方库运行报错:Error running pod install
前端·flutter
符方昊10 小时前
React 19 对比 React 16 新特性解析
前端·react.js
ssshooter10 小时前
又被 Safari 差异坑了:textContent 拿到的值居然没换行?
前端
曲折10 小时前
Cesium-气象要素PNG色斑图叠加
前端·cesium
Forever7_10 小时前
Electron 淘汰!新的桌面端框架 更强大、更轻量化
前端·vue.js
Angelial10 小时前
Vue3 嵌套路由 KeepAlive:动态缓存与反向配置方案
前端·vue.js
jiayu11 小时前
Angular学习笔记24:Angular 响应式表单 FormArray 与 FormGroup 相互嵌套
前端