Search code examples
iosiphonecocos2d-iphone

nextLevel Method


How do I make a method that switches levels for me? I'm using cocos2d btw. I'm not talking about the simple replaceScene, I want a method that, when called, will change from say level 10 to level 11. I'm not sure how to achieve this, but my levels are simply named LevelOne, LevelTwo, LevelThree, etc. I thought about doing

-(void)nextLevel:(ccTime)dt {
    if (currentLevel += 1) { //CURRENT LEVEL + ONE LEVEL 

    }
}

but of course, just adding one to currentLevel (an int I have that has the current level the user is at) would just make the number +1. I don't want a method that detects the level, I want a method that takes currentLevel and goes to the nextLevel.


Solution

  • One nice way would be to store your data in a linked list. Here's a nice article on how to implement one in Core Data. I'm actually using this in my app currently; while the setup is a little complex, the extreme benefit comes with lines of code like this:

    IPhoneGameScene *nextScene = [IPhoneGameScene sceneWithPuzzle:[self.puzzle next]];
    [[CCDirector sharedDirector] replaceScene:nextScene];
    

    So clean!