Transitions
In Cocos2d, we can create transitions between scenes, in order to replace the current scene with the following one. You can think of transitions in games as transitions between slides in a presentation, so we can animate them.
We can create six types of animations thanks to the class methods available: transitionCrossFadeWithDuration
, transitionFadeWithColor:duration
, transitionFadeWithDuration
, transitionMoveInWithDirection:duration
, transitionPushWithDirection:duration
, and transitionRevealWithDirection:duration
.
You can play with these methods, but we are going to use transitionMoveInWithDirection
for this game, so you need to replace the following lines in goToNextLevel
:
[[CCDirector sharedDirector] pushScene:nextLevelScene];
Instead, use the following lines:
// Create transition CCTransition *transition = [CCTransition transitionMoveInWithDirection:CCTransitionDirectionLeft duration:0.5f]; // Push scene with transition [[CCDirector sharedDirector] pushScene:nextLevelScene...