Cocos2d Pop Scene With Transition

Pasting this here for my future reference. Originated from the cocos2d-iphone forum.

Add this to CCDirector.h, just after the declaration -(void)popScene (line 402):

- (void) popSceneWithTransition: (Class)c duration:(ccTime)t;

Then add this to CCDirector.m, just after the definition of -(void)popScene (line 768):

-(void) popSceneWithTransition: (Class)transitionClass duration:(ccTime)t {
    NSAssert( runningScene_ != nil, @"A running Scene is needed");
    [scenesStack_ removeLastObject];
    NSUInteger c = [scenesStack_ count];
    if( c == 0 )
    {
        [self end]; 
    }
    else
    {
        CCScene* scene = [transitionClass transitionWithDuration:t scene:[scenesStack_ objectAtIndex:c-1]];
        [scenesStack_ replaceObjectAtIndex:c-1 withObject:scene]; nextScene_ = scene; 
    }
}

You can call the method like this:

[[CCDirector sharedDirector] popSceneWithTransition:[CCSlideInRTransition class] duration:0.5f];