A couple of weeks back I wrote this post about how to calculate the actual frame rate of your game rather than just hoping that the target frame rate found in display.fps will be met. Back then I only used it as en experiment, but today I wanted to implement it in my game Ice Trap to be able to reduce or disable some animations on slower running devices. I ended up rewriting the frame rate calculator in an object-oriented fashion to make it cleaner and more reusable.
It should be very easy to use. Just create a new instance of the FPSCalculator, passing in a callback function and some optional configuration parameters. In the callback function you'll have access to the current FPS as well as the FPS ratio, i.e (actual_FPS/target_FPS). If none of the optional config parameters are specified the callback will be invoked once every second, regardless of whether there's been a FPS drop or not.
Check out the whole source code below, including some example usage code, and make modifications and extensions to it as you see fit.
It should be very easy to use. Just create a new instance of the FPSCalculator, passing in a callback function and some optional configuration parameters. In the callback function you'll have access to the current FPS as well as the FPS ratio, i.e (actual_FPS/target_FPS). If none of the optional config parameters are specified the callback will be invoked once every second, regardless of whether there's been a FPS drop or not.
Check out the whole source code below, including some example usage code, and make modifications and extensions to it as you see fit.
Comments
Post a Comment