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

相关推荐
我命由我123451 天前
Android Cordova 开发 - Cordova 快速入门(Cordova 环境配置、Cordova 第一个应用程序)
android·开发语言·前端框架·android studio·h5·安卓·android-studio
百锦再2 天前
SQLiteDatabase 增删改查(CRUD)详细操作
android·xml·java·ide·android studio·安卓
百锦再4 天前
Android Drawable 目录下的 XML 图形文件详解
android·xml·java·app·手机·安卓
百锦再4 天前
Android ImageButton 使用详解
android·java·app·安卓·studio·mobile
百锦再7 天前
Android Studio 实现自定义全局悬浮按钮
android·java·ide·app·android studio·安卓
百锦再8 天前
Android ImageView 使用详解
android·java·app·手机·安卓·studio
百锦再9 天前
Android Studio 日志系统详解
android·java·ide·app·android studio·安卓·idea
Superxpang10 天前
JavaScript `new Date()` 方法移动端 `兼容 ios`,ios环境new Date()返回NaN
开发语言·前端·javascript·ios·typescript·安卓
limit007510 天前
免费下载地图切片数据以及通过CesiumEarth在Windows和安卓本地浏览
低代码·3d·arcgis·web3·安卓
派小汤20 天前
The emulator process for AVD xxx has terminated
安卓·android-studio