• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
养眼大魔王
博客园    首页    新随笔    联系   管理    订阅  订阅

cocos2dx新研发的游戏,手机运行时非常热的解决方案

cocos2dx新研发的游戏,手机运行时非常热,有需要的朋友可以参考下。

cocos2dx新研发的游戏,手机上运行时导致手机非常热,后来听其他项目组分享时得知,可以通过降帧解决这个问题,原来是cocos2dx默认的60,后来修改为30,测试发现,手机发热问题解决了。

修改代码:

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;

}

 

posted @ 2014-12-30 16:41  养眼大魔王  阅读(1190)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3