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 – allowing the player to pause and resume


To allow the player to pause and resume the game, we need to follow these steps:

  1. Open the Ship.h file.

  2. Add an instance variable called _juggler that is a pointer to SPJuggler, as shown in the following line of code:

    SPJuggler *_juggler;
  3. Declare a property called paused, which is of the type BOOL, as shown in the following line of code:

    @property (nonatomic) BOOL paused;
  4. Declare a method called advanceTime, as shown in the following line of code:

    -(void) advanceTime:(double)seconds;
  5. Switch to the Ship.m file.

  6. Inside the initializer, set the paused property to NO using its instance variable, as shown in the following code:

    _isShooting = NO;
    _paused = NO;
    
    SPTextureAtlas *atlas = (type == ShipPirate) ? [Assets textureAtlas:@"ship_pirate_small_cannon.xml"] : [Assets textureAtlas:@"ship_small_cannon.xml"];
  7. Initialize the _juggler instance variable inside the initializer with the following line of code:

    _juggler = [SPJuggler juggler];
  8. Update all references...