This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorials:finding_out_the_fps [2013/03/05 10:19] – external edit 127.0.0.1 | tutorials: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 " | ||
+ | |||
+ | <code objc> | ||
+ | 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: | ||
+ | |||
+ | <code objc> | ||
+ | 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): | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | ===== Sparrow 1.x ===== | ||
+ | |||
+ | To set the desired frame rate, use the property on the stage: | ||
+ | |||
+ | <code objc> | ||
+ | [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: | ||
+ | |||
+ | <code objc> | ||
+ | - (void)onEnterFrame: | ||
+ | { | ||
+ | static int frameCount = 0; | ||
+ | static double totalTime = 0; | ||
+ | | ||
+ | totalTime += event.passedTime; | ||
+ | ++frameCount; | ||
+ | | ||
+ | if (totalTime > 1.0) | ||
+ | { | ||
+ | NSLog(@" | ||
+ | frameCount = totalTime = 0; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | This will display the actual frames per second to the console. | ||
+ | |||
+ | <note tip> | ||
+ | Here is a [[https:// | ||
+ | </ |