標籤:
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一致)
@Overridepublic 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 controllingif (interval < Cocos2dxRenderer.sAnimationInterval) {try {// because we render it before, so we should sleep twice time intervalThread.sleep((Cocos2dxRenderer.sAnimationInterval - interval) / Cocos2dxRenderer.NANOSECONDSPERMICROSECOND);} catch (final Exception e) {}}//this.mLastTickInNanoSeconds = nowInNanoSeconds;//*/}
以上,謝謝
本文地址:http://blog.csdn.net/you_and_me12/article/details/37885461
Cocos2d-X學習——Android不同裝置FPS不同問題