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 – the enemy should attack the player

For the enemy to attack the players' ship, use the following steps:

  1. Open the Ship.h file.
  2. Refactor our _juggler instance variable to be a property, as shown in the following line of code:
    @property SPJuggler *juggler;
  3. Using the following line of code, add a method called shootWithBlock that should shoot and have a callback as its parameter:
    -(void) shootWithBlock:(ShipCallback) block;
  4. Open the Ship.m file and move the contents of the shoot method into the shootWithBlock method.
  5. In the shootWithBlock method, invoke the callback as its last statement inside the complete listener of the currentClip variable.
  6. Update the shoot method to call the shootWithBlock method with nil.
  7. Open the Battlefield.m file ...

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