Transitions and setting up Layers/Scenes in cocos2d iPhone

11,132

For those who might care, here's what I ended up doing:

GameScene * gs = [GameScene node];
[[Director sharedDirector] runScene: gs];
[[Director sharedDirector] replaceScene: [ShrinkGrowTransition transitionWithDuration:0.5 scene: gs]];

This was done within the GameLayer implementation after a level was complete.

Share:
11,132
user21293
Author by

user21293

Updated on June 04, 2022

Comments

  • user21293
    user21293 almost 2 years

    I am looking to setup a transition between two levels(after one level is complete, use one of cocos2d's slick transition to transition into the next level). In my GameLayer implementation, I have methods setup to do things like [self buildLevel: 3] to build the playfield. What do I need to do to instantiate a new GameLayer or Layer node or GameScene or Scene node to be able to do things such as:

    GameLayer * nextLevelLayer;

    [nextLevelLayer buildLevel: 4];

    ... do a transition between the level 3 and level 4

    Perhaps I've laid out my code in a complete misunderstanding of Objective C. I am assuming you can't setup a new GameLayer in the init code, as it will hang, continuously created new nodes. I probably have too much playfield setup code in my init code for the GameLayer, how do you guys usually handle it? Do you set a flag before scheduling the selector for the game's main loop, then if the flag is set, setup the level in the game's main loop, or is there a better way to go about it?

    Thanks in advance!