Cocos2D for iPhone is great for 2D game developpement on the iPhone. And what’s the first thing a user will see when he starts your game? That’s right, a menu!
Create a menu with cocos2D is really simple. You first create a Scene and a Layer for your menu (with a nice background image if possible). Then you can create your menu items (MenuItem class) :
MenuItem *startGame = [MenuItemFont itemFromString:@"Start Game" target:self selector:@selector(startGame)];
MenuItem *help = [MenuItemFont itemFromString:@"Help" target:self selector:@selector(help)];
MenuItem *about = [MenuItemFont itemFromString:@"About" target:self selector:@selector(about)];
When you menu items are created, you just need to add them in your menu (Menu class) and customize the layout :
Menu *menu = [Menu menuWithItems: startGame, help, about, nil];
[menu alignItemsVertically];
Finally, you add your menu to your layer :
[self addChild:menu];
That’s it your menu has been created. This code snippets don’t give the implementation of the methods triggered when pressing the buttons (target: selector: ) but here is what you will probably do :
-(void)startGame{
[[Director sharedDirector] replaceScene:[GameScene node]];
}
But you can do whatever you want e.g. create a transition or a UIKit view. But that’s another story…