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~~4 天前
安卓/Java语言基础八股文
java·开发语言·安卓
凛_Lin~~4 天前
安卓 面试八股文整理(基础组件篇)
java·安卓
习惯就好zz6 天前
在 RK3588 上彻底禁用 HDMI 音频输出
音视频·rk3588·安卓·hdmi·禁用音频输出
爱跑马的程序员7 天前
Kernel i2c 设备驱动详细讲解
linux·安卓·内核驱动
私人珍藏库11 天前
【安卓】Lightroom摄影师版PS滤镜免费
android·app·安卓·工具·软件
阿桂有点桂14 天前
Flutter使用VS Code打包app
vscode·flutter·安卓
私人珍藏库15 天前
[Android] 轻小说文库(1.23)
android·app·安卓·工具
做cv的小昊15 天前
在NanoPC-T6开发板上通过USB串口通信实现光源控制功能
java·后端·嵌入式硬件·边缘计算·安卓·信息与通信·开发
Smart-佀16 天前
Android初学必备:选Kotlin 还是Java ?
android·android studio·安卓
qq_2148032919 天前
ArcGIS坐标偏移终极解决方案:Runtime与GDB互转无偏移实践
python·arcgis·安卓