今天又遇到一个神坑,通过setAnimationInterval设置帧频为30帧,发现在android下没有效果。
最后在Cocos2dxRenderer .java文件里面找到了这个函数。里面有句注释 FPS controlling algorithm is not accurate, and it will slow down FPS
on some devices. So comment FPS controlling code.发现其实这段代码已经被屏蔽掉了。。。。
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();
/*
// 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;
*/
}
---------------------------------------------------------------------------------------------------------
所以只能在程序逻辑上多做控制,用时间去控制动作和其他逻辑。