To structure the code of our ship, follow these steps:
Add a new group called
Entities
.Inside this group, add a new Objective-C class called
Ship
, which is derived fromSPSprite
.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;
Declare an alternative initializer called
initWithContentsOfFile
, which takes anNSString
as its parameter:-(id)initWithContentsOfFile:(NSString *)filename;
Declare a method called
shoot
, as shown in the following code:-(void) shoot;
Declare another method called
moveTo
that takes thex
value as its first parameter and they
value as its second parameter, as shown in the following code:-(void) moveToX:(float) x andY:(float) y;
Declare a method called
stop
, as shown in the following code:-(void) stop;
Define the default initializer for the
Ship
class with the following lines...