Hi all, I have a question concerning the creation of levels, and the passing of level-specific data to the level.
I have been working for the last few weeks on a gameScene, and now that I have it (almost) perfected, I want to replicate it to make it into levels. The style of the game is that mostly everything in the game is the same save for a few variables that change # of sprites etc.
My first question concerns the creation of instances of the gameScene. I am currently doing this in my menuScene, when a level button is pressed, by calling this function:
-(void)level2: (id)sender {
GameScene *gs2 = [[GameScene alloc] init];
[[Director sharedDirector] replaceScene:[FlipYTransition transitionWithDuration:1 scene:gs2]];
}
This works great, so all I really need to know is it this is a good strategy or is it possible to create the scenes in an array and if so should I do this beforehand? The plan is for 20+ levels.
My second question concerns getting level-specific variables into (accessible by) the gameScene and it's layers. When I was creating the gameScene I just defined the variables I needed in the .h using define, such as: #define kNumberOfSprites 2
This was great for making the gameScene, and perfecting the game mechanic, but now I need to be able to change that definition depending on the level selected. I also need it to continue to be accessible by the layers within the scene. This is where I need help.
I am trying to create properties within gameScene and synthesize etc, and then in the menuScene pass the info like this:
-(void)level2: (id)sender {
GameScene *gs2 = [[GameScene alloc] init];
gs2.numSprites = 4; //<-- sets the number of sprites specific to this level. Property is int numSprites
[[Director sharedDirector] replaceScene:[FlipYTransition transitionWithDuration:1 scene:gs2]];
}
I have used properties of subclassed sprites before without problems, so didn't think this would be difficult, but I'm struggling and I feel like I'm on the wrong track. Is there a better (working!) way of changing If anyone could lend a hand I'd appreciate it.
Thank you, jonathan