Game Development Reference
In-Depth Information
The DoodleDrop game had only one scene and one layer. More complex games need
several scenes and multiple layers. How and when to use them will become second
nature for you. Let's see what's involved.
Adding More Scenes
In Listings 4-1 and 4-2 in the previous chapter, I outlined the basic code needed to cre-
ate a scene. Those basics still apply. Adding more scenes is a matter of adding more
classes built on that same basic code. It's when you're transitioning between scenes
that things get a little more interesting. There's a set of three methods in CCNode that
are sent to each node object (sprite, label, menu item, and so on) in the current scene
hierarchy when you're replacing a scene via the CCDirector replaceScene
method. You can use these methods to react to scene changes, remove some memory,
or load additional assets in the new scene.
The onEnter and onExit methods get called at certain times during a scene change,
depending on whether a CCTransitionScene is used. You must always call the
super implementation of these methods to avoid input problems and memory leaks.
Take a look at Listing 5-1 and note that all these methods call the super implementa-
tion.
Listing 5-1. The onEnter and onExit Methods
-(void) onEnter
{
// Sent to new scene right after its init method was run.
// If using a CCTransitionScene: sent when the transition begins.
[super onEnter];
}
-(void) onEnterTransitionDidFinish
{
// Sent to the new scene right after onEnter.
// If using a CCTransitionScene: sent when the transition has ended.
[super onEnterTransitionDidFinish];
 
 
Search Nedrilad ::




Custom Search