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 – using our bitmap font for a text field


Follow these steps to display bitmap fonts in SPTextField:

  1. We need to add another property called title inside the Dialog.h file, which is also a pointer to SPTextField:

    @property SPTextField *title;
  2. We register our bitmap font, as shown in the following code:

    [SPTextField registerBitmapFontFromFile:@"PirateFont.fnt"];
  3. We create and position the _title instance with the following lines of code:

    _title = [SPTextField textFieldWithWidth:background.width * 0.6 height:30.0f text:@"Dialog"];
    _title.fontName = @"PirateFont";
    _title.color = SP_WHITE;
    
    _title.x = 24.0f;
    _title.y = 26.0f;
  4. We need to add the _title instance to the display tree, as shown in the following code:

    [self addChild:background];
    [self addChild:buttonYes];
    [self addChild:buttonNo];
    [self addChild:_content];
    [self addChild:_title];
    
  5. Inside the Battlefield.m file, we replace the default title with a custom one:

    _dialogAbort = [[Dialog alloc] init];
            
    _dialogAbort.title.text...