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 – creating a ship class

To structure the code of our ship, follow these steps:

  1. Add a new group called Entities.
  2. Inside this group, add a new Objective-C class called Ship, which is derived from SPSprite.
  3. Open the Ship.h file. Add one instance variable for the ship image and another for the movie clip of the ship shooting cannonballs, as shown in the following code:
    SPMovieClip *_shootingClip;
    SPImage *_idleImage;
  4. Declare an alternative initializer called initWithContentsOfFile, which takes an NSString as its parameter:
    -(id)initWithContentsOfFile:(NSString *)filename;
  5. Declare a method called shoot, as shown in the following code:
    -(void) shoot;
  6. Declare another method called moveTo that takes the x value as its first parameter and the

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