获得打印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);
}
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);
}
相关文章推荐
- 19、Cocos2dx 3.0游戏开发找小三之Action:流动的水没有形状,漂流的风找不到踪迹、、、
- Cocos2dx游戏开发浅谈之地图
- 1、Cocos2dx 3.0游戏开发找小三之前言篇
- Cocos2dx 3.0游戏开发找小三之Cocos2d-x的动作机制:嘻,善哉!技盖至此乎?
- 税后20k诚聘游戏技术总监兼cocos2dx客户端主程
- Cocos2dx游戏开发系列笔记9:android手机上运行《战神传说》,并解决横竖屏即分辨率自适应问题
- Mac下创建多平台cocos2dx游戏项目
- Cocos2dx游戏源码合集
- cocos2dx Android游戏截屏分享
- cocos2dx游戏开发简单入门视频教程 (cocos2d-x)- 第1天
- 3、Cocos2dx 3.0游戏开发找小三之搭建开发环境
- cocos2dx游戏开发——微信打飞机学习笔记(六)——PlayerLayer的搭建
- Android应用内嵌cocos2dx游戏项目
- 6、Cocos2dx 3.0游戏开发找小三之游戏的基本概念
- cocos2dx 3D战斗类游戏制作:【二】——3D运动模式小准备之二
- cocos2dx视频教程进阶篇--第2天--打砖块游戏-box2d物理引擎
- 如何使用cocos2dx 制作一个多向滚屏坦克类射击游戏-第一部分
- 增强现实游戏公司获得了350万美元的投资(译 05-26-2010)
- Cocos2dx系列笔记7:一个简单的跑酷游戏《萝莉快跑》的消化(附下载)
- 19、Cocos2dx 3.0游戏开发找小三之Action:流动的水没有形状,漂流的风找不到踪迹、、、