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

相关推荐
这儿有一堆花4 天前
安卓应用卡顿、性能低下的背后原因
android·安卓
帅得不敢出门11 天前
Android Framework学习三:zygote剖析
android·java·学习·framework·安卓·zygote
shandianchengzi12 天前
【记录】Google|下载 Google 谷歌商店中的应用的多种方式
android·google·安卓·apk
帅得不敢出门13 天前
Android Framework学习二:Activity创建及View绘制流程
android·java·学习·framework·安卓·activity·window
我命由我1234515 天前
Android 解绑服务问题:java.lang.IllegalArgumentException: Service not registered
android·java·开发语言·java-ee·安卓·android jetpack·android-studio
低级前端15 天前
uniapp如何获取安卓原生的Intent对象
前端·uni-app·安卓·web app
车轮滚滚__16 天前
uniapp 小程序 安卓苹果 短视频解决方案
ios·小程序·uni-app·安卓·html5
我命由我1234522 天前
Android Cordova 开发 - Cordova 快速入门(Cordova 环境配置、Cordova 第一个应用程序)
android·开发语言·前端框架·android studio·h5·安卓·android-studio
百锦再24 天前
SQLiteDatabase 增删改查(CRUD)详细操作
android·xml·java·ide·android studio·安卓
百锦再1 个月前
Android Drawable 目录下的 XML 图形文件详解
android·xml·java·app·手机·安卓