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 (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 – moving the pirate ship


Let's follow these steps to move the ship:

  1. Open our game project file if it's not already open.

  2. Add an instance variable called _pirateShip of the type SPImage, as shown in following line of code:

    SPImage* _pirateShip;
  3. Update the references from pirateShip to _pirateShip in Battlefield.m:

    _pirateShip = [SPImage imageWithTexture:[Assets texture:@"ship_pirate.png"]];
    _pirateShip.x = (Sparrow.stage.width - _pirateShip.width) / 2;
    _pirateShip.y = (Sparrow.stage.height - _pirateShip.height) / 2;
  4. Add a method called onBackgroundTouch in the Battlefield.m file, as shown in the following line of code:

    -(void) onBackgroundTouch: (SPTouchEvent*) event
  5. Within this method, get the touch itself:

    SPTouch* touch = [[event touchesWithTarget:self andPhase:SPTouchPhaseBegan] anyObject];
  6. Complete the onBackgroundTouch method with the following piece of code:

    if (touch) {
      SPTween* tweenX = [SPTween tweenWithTarget:_pirateShip time:2.0f];
      SPTween* tweenY = [SPTween tweenWithTarget...