O'Reilly logo

Cocos2d Cross-Platform Game Development Cookbook - Second Edition by Siddharth Shekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Transitioning between scenes

We will discuss how to transition between scenes in this section.

Getting ready

Most of the work is already done in the previous section, so let's dive right into creating the code. However, as we want to transition into GameplayScene, we have to import the class into the MainScene.m file, as follows:

#import "GameplayScene.h"

How to do it…

Next, add the following highlighted code to the playBtnPressed function in the MainScene.m file:

-(void)playBtnPressed:(id)sender{

  CCLOG(@"play button pressed");

  [[CCDirector sharedDirector] replaceScene:
    [[GameplayScene alloc] 
    initWithLevel:@"1"]];
}

How it works…

Now, when we press the play button, GameplayScene will load, display the GameplayScene text, and show that it has loaded ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required