Book Image

Sparrow iOS Game Framework Beginner's Guide

By : Johannes Stein
Book Image

Sparrow iOS Game Framework Beginner's Guide

By: Johannes Stein

Overview of this book

Table of Contents (20 chapters)
Sparrow iOS Game Framework Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Afterword
Index

Time for action – integrating the main menu into our game


Use the following steps to add a main menu:

  1. Add a new class called MainMenu which should be a subclass of Scene.

  2. Switch to MainMenu.m.

  3. Import Assets.h and SceneDirector.h.

  4. 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.x = (Sparrow.stage.width - buttonNewGame.width) / 2;
            buttonNewGame...