Cocos2d-X学习——Android不同设备FPS不同问题
2014-07-16
环境:Cocos2dx 2.2.4
AppDelegate.cpp中FPS设置为 60
pDirector->setAnimationInterval(1.0 / 60);
问题:在两台Android机器上跑。 两台的FPS不一样
I9100: 4.0系统,FPS 约60,(改动FPS为30,也会改变)
S5700: 2.3系统,FPS 约80,(改动FPS为30,照样80)
这样就导致了在游戏刷帧的时候,两台机器跑的速度不一样了。
解决方法例如以下(应该仅仅有Android有这个问题)
改动Android中cocos2dx的 Cocos2dxRenderer.java代码
(PS:假设依照官方的凝视改动,也不能达到FPS一致)
@Override public void onDrawFrame(final GL10 gl) { /* * FPS controlling algorithm is not accurate, and it will slow down FPS * on some devices. So comment FPS controlling code. */ // /* final long nowInNanoSeconds = System.nanoTime(); // final long interval = nowInNanoSeconds - this.mLastTickInNanoSeconds; // */ // should render a frame when onDrawFrame() is called or there is a // "ghost" Cocos2dxRenderer.nativeRender(); final long afterInNanoSeconds = System.nanoTime(); final long interval = afterInNanoSeconds - nowInNanoSeconds; // /* // fps controlling if (interval < Cocos2dxRenderer.sAnimationInterval) { try { // because we render it before, so we should sleep twice time interval Thread.sleep((Cocos2dxRenderer.sAnimationInterval - interval) / Cocos2dxRenderer.NANOSECONDSPERMICROSECOND); } catch (final Exception e) { } } // this.mLastTickInNanoSeconds = nowInNanoSeconds; // */ }
以上,谢谢
本文地址:http://blog.csdn.net/you_and_me12/article/details/37885461