0

I hope to make some custom picture(e.x some logo and information of the game developer)before game is launched.In the cocos2d temple,there is only a IntroLayer to show logo,so I decide to add more scene to display other information before entering the main menu of the game.In IntroLayer.h

//this is the template code    
@interface IntroLayer : CCLayer
{
}

+(CCScene *) scene;

@end

//this is the new scene,I hope to display after the IntroLayer
@interface SecondScene : CCLayer
{
}

+(CCScene*) scene;

@end

//In IntroLayer.m
@implementation IntroLayer

//I change the replaceScene function from [HelloWorldLayer node] to[SecondScene scene]
-(void) onEnter
{
    [super onEnter];
    [[CCDirector sharedDirector] replaceScene:
     [CCTransitionFade transitionWithDuration:1.0 scene:[SecondScene scene]]];
}
@end

@implementation SecondScene

+(CCScene*)scene
{
    CCScene *scene = [CCScene node];
    SecondScene *layer = [SecondScene node];
    [scene addChild:layer];
    return scene;
}

-(id)init
{
    if (self = [super init]) {
        CGSize size = [[CCDirector sharedDirector] winSize];
        CCSprite *background = [CCSprite spriteWithFile:@"LOGO.png"];
        background.position = ccp(size.width/2, size.height/2);
        [self addChild: background];
    }
    return  self;
}

//I hope the main game scene display after the SecondScene
-(void)onEnter{
    [[CCDirector sharedDirector] replaceScene:
     [CCTransitionFade transitionWithDuration:1.0 scene:[HelloWorldLayer scene]]];
    [super onEnter];
}

@end

But when I run this code,I found it doesn't run as I expected.The SecondScene and the HelloWorldLayer display nearly at the same time,actually at last there is only SecondScene left in the screen and the HelloWorldLayer quickly disappear.I am really confused with that.Can anyone give some advice?Really Thanks for that.

godel9
  • 7,340
  • 1
  • 33
  • 53

1 Answers1

0

If you want the second transition to follow the first, you need to override the onEnterTransitionDidFinish method:

-(void)onEnterTransitionDidFinish{
    [super onEnterTransitionDidFinish];
    [[CCDirector sharedDirector] replaceScene:
     [CCTransitionFade transitionWithDuration:1.0 scene:[HelloWorldLayer scene]]];
}
godel9
  • 7,340
  • 1
  • 33
  • 53
  • Thanks!I did hope after first scene transition finish display second scene,and after second scene transition finish display game scene.But I found that when perform the second scene transition to the game scene,it never comes to the onExit function of the second scene.It also never comes to the onEnterTransitionDidFinish function of the game scene,it seems that the transition from the second scene to the game scene never ends and the second scene and game scene mix together on the screen.Do you know you why this happens?How can I make the game scene display after the second scene transition? – user3050371 Dec 30 '13 at 03:09