Search code examples
iphonecocos2d-iphonebox2dlevels

How to create multiple levels with Cocos2d


I'm creating a simple puzzle game that uses Cocos2d and Box2d but I'm struggling to find any documentation on how to organise levels.

The game is similar to Cut the Rope in structure, it has multiple fixed size levels with changing Box2d assets.

Currently my mainGame.m file contains my HUD and methods for creating obstacles. Would the best answer be to call some sort of .plist file for each level that lists the assets to be created, and their respective position, then use a for loop to reference the method in the mainGame.m file?

Or could I create a level class on a seperate xxxxxx.m file that references the methods in my mainGame.m?

I apologise if this is vague/hard to understand, I'm very confused at the moment and not sure how to move forward :/


Solution

  • A few possibilities come to mind...

    • Have either a separate CCScene instance for each of your levels or a separate CCLayer for each of your levels.
    • Another possibility is having a custom class which just holds metadata about each level. You than re-create all your level data on a single CCLayer instance from a single game scene. This is what we are doing for Mega Jump.

    As painful as it might be I would not get into the fine details of storing metadata for your level in a plist file. Hard code values for any static placement of UI or other components you need to do. Likely your time is better spent refining the game itself. Hopefully some of those ideas are useful to you. Certainly let me know if anything doesn't make sense or if you want me to go in depth into one of those items a bit more.