Game Development Reference
In-Depth Information
scene inside the CCLayer object. I mention this method in Chapter 2 , but here it is
again to refresh your memory:
+(id) scene
{
CCScene *scene = [CCScene node];
CCLayer* layer = [HelloWorld node];
[scene addChild:layer];
return scene;
}
The very first place you'll create a scene is at the end of the app delegate's applica-
tionDidFinishLaunching method. You use Director to start the first scene with
the runWithScene method:
// only use this to run the very first scene
[[CCDirector sharedDirector] runWithScene:[HelloWorld scene]];
For all subsequent scene changes, you must replace the existing scene with the aptly
named replaceScene method:
// use replaceScene to change all subsequent scenes
[[CCDirector sharedDirector] replaceScene:[HelloWorld scene]];
As you'll soon learn in an upcoming section, you can also use transitional effects when
replacing scenes. The following is an example that uses the CCTrans-
itionShrinkGrow class as an intermediary scene that manages the transition anim-
ation:
CCScene* scene = [HelloWorld scene];
CCSceneTransition* tran = [CCTransitionShrinkGrow transitionWithDuration:2 scene:scene];
[[CCDirector sharedDirector] replaceScene:tran];
Caution If you run the preceding code in the HelloWorld scene , it will
work just fine, creating a new instance of HelloWorld and replacing the old
one, effectively reloading the scene. However, don't try to reload the current
Search Nedrilad ::




Custom Search