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

相关推荐
青枣八神12 小时前
Expo如何只通过数据线连接手机的Expo go
react native·智能手机·安卓
Roki Zhang16 小时前
自开发网盘APP使用说明
安卓·个人开发·网盘
雁鸣零落16 小时前
浏览器扩展 CaptionGo,在网页视频上显示双语字幕,支持 PC 和手机端使用
android·chrome·edge·firefox·安卓
阿拉斯攀登4 天前
无人售货柜MQTT客户端工业级配置:心跳、遗嘱、重连、QoS适配实战
嵌入式硬件·mqtt·安卓·零售·无人售货柜·无人售货机
阿拉斯攀登4 天前
无人售货柜设备开机自动注册逻辑:唯一标识绑定、防重复、批量铺货适配
嵌入式硬件·安卓·零售·安卓驱动·无人售货柜·无人售货机
杨江4 天前
安卓app如何做自动升级
安卓
狂热开发者5 天前
用 Typeoff 把会后口述整理成 Markdown 决策记录
人工智能·windows·macos·ios·安卓
超级数据查看器9 天前
超级数据查看器 v10.0 发布
java·大数据·数据库·sqlite·安卓
普马萨特1 个月前
Wi-Fi 扫描频率多层限制机制解析
网络协议·安卓
ᴀᴠɪᴄɪɪ ғᴏʀᴇᴠᴇʀ1 个月前
WebHomeTV:把 Android 影音盒子变成一个可编程的网页应用平台
app·安卓·智能tv·tv box·webtv