Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transitions and setting up Layers/Scenes in cocos2d iPhone

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!

like image 792
user21293 Avatar asked Dec 09 '08 22:12

user21293


1 Answers

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.

like image 50
user21293 Avatar answered Oct 21 '22 03:10

user21293