Time for action – integrating the main menu into our game
Use the following steps to add a main menu:
- Add a new class called
MainMenu
which should be a subclass ofScene
. - Switch to
MainMenu.m
. - Import
Assets.h
andSceneDirector.h
. - Add the initializer for the main menu, as shown in the following code:
-(id) init { if ((self = [super init])) { SPImage *background = [SPImage imageWithTexture:[Assets texture:@"water.png"]]; SPTexture *shipTexture = [[Assets textureAtlas:@"ship_pirate_small_cannon.xml"] textureByName:@"ne_0001"]; SPImage *ship = [SPImage imageWithTexture:shipTexture]; ship.x = 16.0f; ship.y = (Sparrow.stage.height - ship.height) / 2; SPTexture *dialogTexture = [[Assets textureAtlas:@"ui.xml"] textureByName:@"dialog_yes"]; SPButton *buttonNewGame = [SPButton buttonWithUpState:dialogTexture text:@"New game"]; buttonNewGame...