Game Development Reference
In-Depth Information
It is worth noting that iOS devices have vertical synchronization (vsync) always enabled.
The framerate counter gives you an average number of frames over multiple frames. In
reality, you can only have a constant framerate of 60, 30, 20, 15, 12, 10, and 6 fps. All of
these values are factors of 60. Due to vsync being enabled, if a frame did not complete its
update-and-render cycle within 0.0166 seconds, it will be displayed at the earliest in an-
other 0.0166 seconds, not as soon as it's done. So once the game starts taking more than
0.0166 seconds to complete every frame, the framerate falls back to 30 fps.
For some games where the framerate fluctuates heavily between 30 to 60 fps, it can make
sense to lock the framerate at a constant 30 fps. This may feel smoother than a constantly
fluctuating framerate that skips a couple frames, and thus drops to 30 fps and then renders
a few more frames at 60 fps. To change the maximum framerate, you can add the lines in
Listing 14-9 to the startScene method in AppDelegate.m .
Listing 14-9 . Restricting framerate to 30 fps
CGFloat framesPerSecond = 30;
[CCDirector sharedDirector].animationInterval = 1.0
/ framesPerSecond;
The division by framesPerSecond is necessary because the animationInterval
is expressed as seconds per frame.
Walking the Scene Graph
Another useful debugging feature of Cocos2D is a function that prints out the nodes and
their children recursively, given a specific starting node. (See Listing 14-10 .) You may
want to add that line to the didLoadFromCCB method in the MainScene or GameS-
cene class, or both.
Listing 14-10 . Logging the scene graph
[self.scene walkSceneGraph:0];
This prints out the scene or node graph recursively, beginning with self.scene . You
can use any other node as the starting point. The parameter ought to be 0 because it's used
only internally to properly indent child nodes. You can see an example output in Listing
14-11 .
Search WWH ::




Custom Search