Book Image

Sparrow iOS Game Framework Beginner's Guide

By : Stein
Book Image

Sparrow iOS Game Framework Beginner's Guide

By: Stein

Overview of this book

An easy-to-follow guide full of descriptive step-by-step procedures on how to develop a game for iOS. With each topic, a new challenge will be tackled to get a deeper knowledge of the Sparrow game framework and gain the skills to develop a complete mobile experience. This book is aimed at those who have always wanted to create their own games for iOS devices. Perhaps you've already dabbled in game development and want to know how to develop games for the Apple App Store, or maybe you have developed Objective-C apps in the past but you are new to game development. In either case, this book will help with descriptive examples and teach you to develop a game throughout its course. Some experience in Objective-C and a basic understanding of object-oriented programming are required.
Table of Contents (15 chapters)
13
Afterword
14
Index

Time for action – adding a text field to the dialog


To draw text on the screen, we need to follow these steps:

  1. As shown in the following line of code, add a property called content, which is a pointer to SPTextField, inside the Dialog.h file:

    @property SPTextField *content;
  2. In the Dialog initializer, create the following content instance and position it between the title box and the buttons:

    _content = [SPTextField textFieldWithWidth:background.width - 48.0f height:background.height - 150.0f text:@"Dialog default text"];
    _content.x = 24.0f;
    _content.y = 50.0f;
  3. Add the content property to the display tree, as shown in the following code:

    [self addChild:background];
    [self addChild:buttonYes];
    [self addChild:buttonNo];
    [self addChild:_content];
    
  4. Switch to the Battlefield.m file.

  5. Add a custom message for the abort dialog, as shown in the following code:

    _dialogAbort = [[Dialog alloc] init];
    
    _dialogAbort.content.text = @"Would you like to abort the current fight?";
    
    _dialogAbort.x = (Sparrow.stage.width...