cocos creator 帧率60 不生效meta50 能刷新到90

环境:

cocos creator 2.4.3

华为meta 50

背景:

小游戏 需要在update 里取帧率 发现跟时间对不上

游戏设置60帧

手机上显示 90帧

cc.game.setFrameRate(30) 显示 30帧

cc.game.setFrameRate(60) 显示 90帧

结论:

对于老版本的cocos creator 如果有依赖帧率的逻辑

需要自行注意逻辑正确性

cc.game.getFrameRate() 取出来的帧率 有可能 并不是当前真实帧率 只是逻辑帧率

源码分析:

java 复制代码
	cocos2dxRenderer.java 

	@Override
    public void onDrawFrame(final GL10 gl) {
        if (mNeedToPause)
            return;

        if (mNeedShowFPS) {
            /
            //IDEA: show FPS in Android Text control rather than outputing log.
            ++mFrameCount;
            long nowFpsTime = System.nanoTime();
            long fpsTimeInterval = nowFpsTime - mOldNanoTime;
            if (fpsTimeInterval > 1000000000L) {
                double frameRate = 1000000000.0 * mFrameCount / fpsTimeInterval;
                Cocos2dxHelper.OnGameInfoUpdatedListener listener = Cocos2dxHelper.getOnGameInfoUpdatedListener();
                if (listener != null) {
                    listener.onFPSUpdated((float) frameRate);
                }
                mFrameCount = 0;
                mOldNanoTime = System.nanoTime();
            }
            /
        }
        /*
         * No need to use algorithm in default(60 FPS) situation,
         * since onDrawFrame() was called by system 60 times per second by default.
         */
        if (sAnimationInterval <= INTERVAL_60_FPS) {
            Cocos2dxRenderer.nativeRender();
        } else {
            final long now = System.nanoTime();
            final long interval = now - this.mLastTickInNanoSeconds;

            if (interval < Cocos2dxRenderer.sAnimationInterval) {
                try {
                    Thread.sleep((Cocos2dxRenderer.sAnimationInterval - interval) / Cocos2dxRenderer.NANOSECONDSPERMICROSECOND);
                } catch (final Exception e) {
                }
            }
            /*
             * Render time MUST be counted in, or the FPS will slower than appointed.
            */
            this.mLastTickInNanoSeconds = System.nanoTime();
            Cocos2dxRenderer.nativeRender();
        }
    }

分析上述代码

java 复制代码
if (sAnimationInterval <= INTERVAL_60_FPS) {
            Cocos2dxRenderer.nativeRender();
}

说明 >= 60帧的设置 。没有处理刷新帧率 走的系统是高刷

所以会导致 dt 并不是 60帧的dt

相关推荐
凛_Lin~~5 小时前
LiveData 源码解析
android·安卓·livedata
秋不溜啾5 天前
三星手机网络连接ADB和关闭自动更新
adb·安卓
MyBili9 天前
【安卓开发/搞机】快图浏览(QuickPic)技术解析:为何这款3MB应用仍是本地图库的性能天花板?
android·app·安卓·文件管理·相册·看图软件·手机相册
深念Y15 天前
NativeScript 移动端开发踩坑记录
前端·ui·vue·安卓·移动端·native·原生
千码君201617 天前
安卓应用市场后端管理系统V1.0阶段性总结
安卓·扩展屏应用开发
Buke..21 天前
【APP 逆向】哔哩哔哩 sign 参数逆向(上):Frida 反调试绕过与 unidbg 调用
java·开发语言·爬虫·python·安卓
爱和冰阔落21 天前
【Linux】Ctrl+C 到底做了什么?从键盘、kill 到 alarm,一次讲清信号的产生
linux·运维·c++·安卓
深念Y23 天前
RIO-UL00(EMUI 4.1 / Android 6.0.1 / arm64)开机自启动 sshd
android·linux·华为·安卓·chroot·sshd·emui
Anhty1 个月前
2026 实测 4 款 AI 变声器|QQ 聊天伪装声线,告别僵硬假声
人工智能·功能测试·ios·智能手机·安卓
Anhty1 个月前
手机端叮咚变声器2026实测:功能表现、优缺点完整解析
功能测试·ios·智能手机·安卓