Game Development Reference
In-Depth Information
cocos2d has rendered will remain as a static image in the CCGLView . That's why hid-
ing the CCGLView is a good idea. Calling stopAnimation is necessary to ensure
that certain UIKit views are responsive and animate smoothly, in particular all views
derived from UIScrollView . It's good practice to call stopAnimation whenever
you hide the cocos2d view, to conserve performance for the foreground views as well
as conserve battery power. Once the foreground view is dismissed, you call
startAnimation again and you can unhide the CCGLView , and the cocos2d view
and director continue where they were.
Tip If you want to see how this app behaves with autorotation, you have to
make a small change to the ViewBasedAppWithCocos2DViewCon-
troller class. Simply return YES from the shouldAutorotateToIn-
terfaceOrientation method to enable rotation to all orientations. Al-
though your app doesn't support it well (it's not designed for landscape orienta-
tion), it serves to show that the cocos2d view will be correctly autorotated.
Changing Scenes
The last step to complete this project is to use the Segmented Control's buttons to
change scenes in the cocos2d view. Listing 15-9 , taken from the ViewController
class, shows the code that was added to the sceneChanged method.
Listing 15-9 . Changing Scenes Whenever You Press a UIKit Button
- (IBAction)sceneChanged:(id)sender
{
CCDirector* director = [CCDirector sharedDirector];
if (director.view.hidden == NO)
{
UISegmentedControl* sceneChanger = (UISegmentedControl*)sender;
int selection = sceneChanger.selectedSegmentIndex;
CCScene* newScene = [HelloWorldLayer scene];
CCScene* trans = nil;
if (selection == 0)
 
 
Search Nedrilad ::




Custom Search