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 – 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...