How to find out the current number of frames per second

Sparrow 2.x

You can set the target frame rate by updating a property on the “SPViewController”:

viewController.preferredFramesPerSecond = 60;

However, this won't tell you what the real framerate is. If there are many objects on the screen or your game logic needs a lot of CPU power, the device won't be able to render as many frames per second as you requested.

To find out the actual frame rate, you can activate the statistics display in Sparrow 2.x:

viewController.showStats = YES;

This will add a small box at the top left of the screen showing the number of frames per second (FPS) and the number of draw calls per frame (DRW):

Statistics Display

Sparrow 1.x

To set the desired frame rate, use the property on the stage:

[SPStage mainStage].frameRate = 60;

The frame rate that is actually reached must be calculated manually. You can use the following code snippet; just add it to an enter frame event handler:

- (void)onEnterFrame:(SPEnterFrameEvent *)event
{
    static int frameCount = 0;
    static double totalTime = 0;
 
    totalTime += event.passedTime;
    ++frameCount;
 
    if (totalTime > 1.0)
    {
        NSLog(@"fps: %.2f", frameCount / totalTime);
        frameCount = totalTime = 0;
    }
}

This will display the actual frames per second to the console.

Here is a simple class that will show you the FPS in sparrow when your device is unplugged.
  tutorials/finding_out_the_fps.txt · Last modified: 2013/05/30 18:47 by daniel
 
Powered by DokuWiki