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
About the Author
About the Reviewers

Time for action – creating a dialog class

To add dialogs, we need to follow these steps:

  1. Add a new group inside the Classes folder called UI.

  2. Inside the UI group, add a new Objective-C class called Dialog, which derives from SPSprite.

  3. Implement the dialog initializer with the following lines of code:

    -(id) init
        if ((self = [super init])) {
            SPImage *background = [SPImage imageWithTexture:[[Assets textureAtlas:@"ui.xml"] textureByName:@"dialog"]];
            SPButton *buttonYes = [SPButton buttonWithUpState:[[Assets textureAtlas:@"ui.xml"] textureByName:@"dialog_yes"] text:@"Yes"];
            SPButton *buttonNo = [SPButton buttonWithUpState:[[Assets textureAtlas:@"ui.xml"] textureByName:@"dialog_no"] text:@"No"];
            buttonYes.x = 24.0f;
            buttonYes.y = background.height - buttonYes.height -40.0f;
            buttonNo.x = buttonYes.x + buttonYes.width - 20.0f;
            buttonNo.y = buttonYes.y;
            [self addChild:background];