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