zoukankan      html  css  js  c++  java
  • cocos2dx 2.1.1 jsbinding 游戏帧数下降问题记录

    游戏在主循环中增加了一个复杂的碰撞检查后,开始出现掉帧,怪物元素量大时,原本60的fps只剩20~30之间;

    引用cocos2d官方的一段话:

    Basically all the cocos2d-iphone, Chipmunk or CocosBuilder Reader APIs are going to perform almost at native speed. But you should pay attention to the following scenarios:

    The performance could be slow down while the garbage collector is run. Workaround: Do not create many JS objects. Reuse as many as possible
    Having a complex main loop could slow down the performance. Workaround: Profile your JS code, and if you can't further optimize it, write the expensive parts in Objective-C and create JS bindings for those functions.

    掉帧现象部分来自于主循环运算量过大,60fps的游戏, 主循环每秒运算60次, 可以减少主循环中不必要的运算;

    怪物每帧移动,施法,判断碰撞等,可以改为每5帧判断一次,运算量会小很多; 

    具体的做法,是在主循环中获取当前时间戳,运行动作后记录时间戳, 下次运行时当前时间和最后记录的时间戳达到一定时间以上,再进行动作;

    本次调整后的游戏表现及体验均未有影响,fps又稳定在58以上;

  • 相关阅读:
    带着萌新看springboot源码
    学习springboot
    第一次来博客园
    第2章 排版样式
    第1章 Bootstrap介绍
    tab左右箭头切换
    $()下的常用方法2
    前端性能优化----yahoo前端性能团队总结的35条黄金定律
    tab
    $()下的常用方法
  • 原文地址:https://www.cnblogs.com/sslin/p/2998346.html
Copyright © 2011-2022 走看看