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 – conceding the game


To abort the current game, we need to follow these steps:

  1. Open the Battlefield.m file.

  2. Inside the initializer, we should add the abort button right after the resume button:

    SPButton *buttonAbort = [SPButton buttonWithUpState:[[Assets textureAtlas:@"ui.xml"] textureByName:@"button_abort"]];
  3. Position the abort button in the bottom-right corner:

    buttonAbort.x = Sparrow.stage.width - buttonAbort.width - 4.0f;
    buttonAbort.y = Sparrow.stage.height - buttonAbort.height - 4.0f;
  4. Import the SceneDirector class, as shown in the following line of code:

    #import "SceneDirector.h"
  5. Add a listener to the abort button using a block, as shown in the following code:

    [buttonAbort addEventListenerForType:SP_EVENT_TYPE_TRIGGERED block:^(SPEvent *event)
    {
      [((SceneDirector *) self.director) showScene:@"piratecove"];
    }];
  6. Add the button to the display tree, as shown in the following code:

    [self addChild:buttonAbort];
  7. Run the example to see the result.

    We now see the abort button as shown...