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 our own buttons to our dialog


To add custom events for our dialogs, we just need to follow these steps:

  1. Inside the Dialog.h file, we need to define the event names before the interface declaration:

    #define EVENT_TYPE_YES_TRIGGERED @"yesTriggered"
    #define EVENT_TYPE_NO_TRIGGERED  @"noTriggered"
  2. Switch to Dialog.m.

  3. Register the following listeners to our buttons:

    [buttonYes addEventListener:@selector(onButtonYes:) atObject:self forType:SP_EVENT_TYPE_TRIGGERED];
    
    [buttonNo addEventListener:@selector(onButtonNo:) atObject:self forType:SP_EVENT_TYPE_TRIGGERED];
  4. Implement the onButtonYes and onButtonNo methods, as shown in the following code:

    - (void)onButtonYes:(SPEvent *)event
    {
        SPEvent *localEvent = [SPEvent eventWithType:EVENT_TYPE_YES_TRIGGERED];
        [self dispatchEvent:localEvent];
    }
    
    - (void)onButtonNo:(SPEvent *)event
    {
        SPEvent *localEvent = [SPEvent eventWithType:EVENT_TYPE_NO_TRIGGERED];
        [self dispatchEvent:localEvent];
    }
  5. Switch to Battlefield.m.

  6. The local...