Cocos2d-x setAnimationInterval在Android上不起作用
发布时间:2020-12-14 18:57:31 所属栏目:百科 来源:网络整理
导读:我尝试使用以下代码在Cocos2d-x中设置应用程序中的最大FPS: CCDirector::sharedDirector()-setAnimationInterval(1.0 / 30); 它适用于iOS,但是当我在三个Android设备上测试它时,它会被忽略,并以标准间隔(1/60)呈现帧. 如何使用cocos2d-x在Android上正确设置
我尝试使用以下代码在Cocos2d-x中设置应用程序中的最大FPS:
CCDirector::sharedDirector()->setAnimationInterval(1.0 / 30); 它适用于iOS,但是当我在三个Android设备上测试它时,它会被忽略,并以标准间隔(1/60)呈现帧. 如何使用cocos2d-x在Android上正确设置最大FPS? 解决方法
所以我实际上已经成功实现了它.您必须编辑Cocos2dxRenderer.java文件,然后清理并重建Cocos2d-x.
这是代码: 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. try { if (loopRuntime < 40) { Log.wtf("RENDERER","Sleeping for == " + (40 - loopRuntime)); Thread.sleep(40 - loopRuntime); } } catch (InterruptedException e) { e.printStackTrace(); } //final long nowInNanoSeconds = System.nanoTime(); //final long interval = nowInNanoSeconds - this.mLastTickInNanoSeconds; loopStart = System.currentTimeMillis(); // should render a frame when onDrawFrame() is called or there is a // "ghost" Cocos2dxRenderer.nativeRender(); loopEnd = System.currentTimeMillis(); loopRuntime = (loopEnd - loopStart); Log.wtf("RENDERER","loopRunTime == " + loopRuntime); // 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; } 奇怪的是,当我取消注释那里的fps控制部件时它没有做任何事情,当我编写我的版本时它确实…… 编辑:我将loopStart行移至睡眠后 – >休眠时间不应包含在loopTime中. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |