Book Image

Sparrow iOS Game Framework Beginner's Guide

By : Johannes Stein
Book Image

Sparrow iOS Game Framework Beginner's Guide

By: Johannes Stein

Overview of this book

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 – 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 y value as its second parameter, as shown in the following code:

    -(void) moveToX:(float) x andY:(float) y;
  7. Declare a method called stop, as shown in the following code:

    -(void) stop;
  8. Define the default initializer for the Ship class with the following lines...