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 – being able to win or lose


To be able to win or lose the game, use the following steps:

  1. In Ship.h, add a callback property using the following line of code:

    @property (nonatomic, copy) ShipCallbackonDead;
  2. This callback property gets invoked if the ship is equal to or less than zero hit points, as shown in the following code:

    if (_hitpoints<= 0) {
      self.visible = FALSE;
      
      if (self.onDead) {
        [_onDead invoke];
      }
    }
  3. In the Battlefield.h file, add two properties for our new text fields as shown:

    @property SPTextField *textGameWon;
    @property SPTextField *textGameLost;
  4. In the initializer, add the following piece of code:

    _textGameLost = [SPTextField textFieldWithWidth:Sparrow.stage.width height:Sparrow.stage.height text:@"Game Over"];
    _textGameLost.fontName = @"PirateFont";
    _textGameLost.color = SP_WHITE;
    _textGameLost.visible = NO;
    
    _textGameWon = [SPTextField textFieldWithWidth:Sparrow.stage.width height:Sparrow.stage.height text:@"You won the game. Well done"];
    _textGameWon...