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 – making the pirate cove playable


To add game mechanics to the pirate cove, use the following steps:

  1. Move the line of code [SPTextField registerBitmapFontFromFile:@"PirateFont.fnt"]; from Dialog.m to the beginning of the Game.m file.

  2. Add a button in PirateCove.m, as shown in the following code:

    SPButton *buttonBattle = [SPButton buttonWithUpState:[[Assets textureAtlas:@"ui.xml"] textureByName:@"dialog_yes"]; 
    text:@"Begin battle"];
    
    buttonBattle.y = Sparrow.stage.height - buttonBattle.height - 8.0f;
    buttonBattle.x = (Sparrow.stage.width - buttonBattle.width) / 2;
    
    [buttonBattle addEventListenerForType:SP_EVENT_TYPE_TRIGGERED block:^(SPEvent *event){
      [((SceneDirector *) self.director) showScene:@"battlefield"];
    }];
  3. Add the button to the display tree using the following line of code:

    [self addChild:buttonBattle];
  4. In the following code, we add a text field to display the current amount of gold, which needs to be declared as an instance variable first:

    _goldTextField = [SPTextField...