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

Adding transition effects

If you think adding transitions was cool, you can add transition effects while transitioning between scenes in Cocos2d, and it is very easy!

Getting ready

All we really have to do is change the replaced code written in the previous code with the code specifying the transition effect we want. This is done using the CCTransition class.

How to do it…

Replace the code in the previous section with the code highlighted in the playBtnPressed function, as follows:

-(void)playBtnPressed:(id)sender{ CCLOG(@"play button pressed"); //[[CCDirector sharedDirector] replaceScene:[[GameplayScene alloc] initWithLevel:@"1"]]; CCTransition *transition = [CCTransition transitionPushWithDirection:CCTransitionDirectionLeft duration:0.20]; [[CCDirector ...

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