码迷,mamicode.com
首页 > 其他好文 > 详细

cocos2dx 锁定30帧设置

时间:2014-07-14 23:16:29      阅读:592      评论:0      收藏:0      [点我收藏+]

标签:java   os   for   io   代码   re   

修改代码:

AppDelegate.cpp

// set FPS. the default value is 1.0/60 if you don‘t call this

pDirector->setAnimationInterval(1.0 / 30);

 

还有就是:Cocos2dxRenderer.java

//private static long sAnimationInterval = (long) (1.0 / 60 * Cocos2dxRenderer.NANOSECONDSPERSECOND);

private static long sAnimationInterval = (long) (1.0 / 30 * Cocos2dxRenderer.NANOSECONDSPERSECOND);

...

@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();

// should render a frame when onDrawFrame() is called or there is a

// "ghost"

Cocos2dxRenderer.nativeRender();

final long afterRenderNano = System.nanoTime();

//final long interval = afterRenderNano - mLastTickInNanoSeconds - Cocos2dxRenderer.sAnimationInterval;// afterRenderNano - nowInNanoSeconds;//nowInNanoSeconds - this.mLastTickInNanoSeconds;

final long interval = afterRenderNano - nowInNanoSeconds;

// fps controlling

if (interval < Cocos2dxRenderer.sAnimationInterval) {

//Log.d("onDrawFrame", "Cancel frame" + 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;

}

 

cocos2dx 锁定30帧设置,布布扣,bubuko.com

cocos2dx 锁定30帧设置

标签:java   os   for   io   代码   re   

原文地址:http://www.cnblogs.com/ADaii/p/3842427.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!