Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorials:finding_out_the_fps [2013/03/05 10:19] – external edit 127.0.0.1tutorials:finding_out_the_fps [2013/05/30 18:47] (current) daniel
Line 1: Line 1:
 +====== 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":
 +
 +<code objc>
 +viewController.preferredFramesPerSecond = 60;
 +</code>
 +
 +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:
 +
 +<code objc>
 +viewController.showStats = YES;
 +</code>
 +
 +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):
 +
 +{{ :manual:stats_display.png?nolink |Statistics Display}}
 +
 +===== Sparrow 1.x =====
 +
 +To set the desired frame rate, use the property on the stage:
 +
 +<code objc>
 +[SPStage mainStage].frameRate = 60;
 +</code>
 +
 +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:
 +
 +<code objc>
 +- (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;
 +    }
 +}
 +</code>
 +
 +This will display the actual frames per second to the console. 
 +
 +<note tip>
 +Here is a [[https://gist.github.com/893868|simple class]] that will show you the FPS in sparrow when your device is unplugged.
 +</note>
  tutorials/finding_out_the_fps.txt · Last modified: 2013/05/30 18:47 by daniel
 
Powered by DokuWiki