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 – updating the movement

To update the movement of our ship, follow these steps:

  1. Inside the initializer, add a tween for the enemy ship. We want the enemy ship to move on its own. We should also rename the ship instance to enemyShip:
    SPImage *enemyShip = [SPImage imageWithTexture:[Assets texture:@"ship.png"]];
    enemyShip.x = 100;
    enemyShip.y = 100;
    
    SPTween *shipTween = [SPTween tweenWithTarget:enemyShip time:4.0f transition:SP_TRANSITION_EASE_IN_OUT];
    [shipTween animateProperty:@"y" targetValue:250];
    shipTween.repeatCount = 5;
    shipTween.reverse = YES;
    shipTween.delay = 2.0f;
    
    [Sparrow.juggler addObject:shipTween];
    
  2. Update the onBackgroundTouch method to resemble the following piece of code:
    SPTouch *touch = [[event touchesWithTarget:self] anyObject];
    
    if (touch) {
      [Sparrow.juggler removeObjectsWithTarget:_pirateShip];
      
      float targetX = touch.globalX - (_pirateShip.width / 2);
      float targetY = touch.globalY - (_pirateShip.height / 2);
      
      float...