Game Development Reference
In-Depth Information
[director runWithScene:[HelloWorldLayer scene]];
[director startAnimation];
director.view.hidden = NO;
[director stopAnimation];
director.view.hidden = YES;
There's only one special case in this code that checks whether there's a currently run-
ning scene. If there's none, you know that this is the first time the user tapped the On/
Off switch and so you must run the first scene. You can easily start and stop the
cocos2d engine at any time.
It gets a lot more complicated if you want to shut down cocos2d entirely and boot it up
again. Most of the time you want to avoid that. You can reduce the memory usage of
cocos2d temporarily by cleaning all caches. All cocos2d cache classes have methods to
uncache unused or all cached assets. Before stopping cocos2d you may also want to
switch to an empty scene to make sure cocos2d isn't referencing any assets for the time
being. If you do that, the memory footprint of cocos2d is pretty minimal, and you can
avoid the hassle of completely shutting down and rebooting cocos2d. Not only would
this add additional loading time, it's also prone to cause a variety of issues. Although
cocos2d supports it, this shutdown and restart behavior is barely tested and gets very
little to no support.
Notice that the director methods startAnimation and stopAnimation are used
to run and stop cocos2d. Just for the very first time when there is no running scene, you
need to call runWithScene . But if you want to run a different scene each time
cocos2d is restarted, you should call replaceScene directly after the call to
startAnimation . The runWithScene method can be called only once during
the lifetime of the application and must not be used again.
Technically, the stopAnimation method only stops cocos2d from refreshing its
view. Unless the view is hidden or obstructed by another view, the last frame
Search Nedrilad ::

Custom Search