O'Reilly logo

Sparrow iOS Game Framework Beginner's Guide by Johannes Stein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required