Switching scenes

A scene is the basic high-level CCNode object. All other nodes are considered children of a scene. Only one scene can be running at a time. Scenes are managed using a stack data structure. In this recipe, we will see how to push and pop scenes onto the stack.

Switching scenes

Getting ready

Please refer to the project RecipeCollection02 for full working code of this recipe.

How to do it...

Execute the following code:

// TreeSceneMenu // The node for our binary tree of scenes @interface TreeSceneMenu : CCLayer { NSString *name; } +(id) sceneWithString:(NSString*)str; -(id) initWithString:(NSString*)str; -(void) goToScene1:(id)sender; -(void) goToScene2:(id)sender; ...

Get Cocos2d for iPhone 1 Game Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.