您的位置:首页 > 移动开发 > Cocos引擎

获得打印cocos2dx游戏中左下角的fps值

2014-07-28 16:58 501 查看
    由于测试需求,要获得获得打印cocos2dx游戏中左下角的fps值。尝试方法

1.在lua代码中开全局定时,记录director:getAnimationInterval() 不可行,获取的只是相对于director->setAnimationInterval(1.0/60)的固定值

2.cc.Director:getInstance():getSecondsPerFrame()   的倒数,保存在table中,在一轮结束后传给log,也不可行。其值在100~2000
3.在cocos2dx中显示的fps值,并不是实时的值,只是在一小段时间的平均值

What cocos2d displays as fps is not an accurate representation of the switch from 60 to 30 to 20 and 15 fps but the average framerate over several frames. Therefore
when cocos2d prints "45 fps" it means half the time the game displayed 30 fps, the other half at 60 fps over the past couple frames.
最终可行获得方法:
直接更改cocos2dx源代码,它没有提供直接的接口,Director.cpp文件中的fps
++_frames;//到此时的总帧数
    _accumDt += _deltaTime;//总的积累延时
        if (_accumDt > CC_DIRECTOR_STATS_INTERVAL)
        {
            _frameRate = _frames / _accumDt;
            _frames = 0;
            _accumDt = 0;

            CCLOG("MYPFS:%.5f",_frameRate);
        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  cocos2dx FPS值获取