-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Sparrow iOS Game Framework Beginner's Guide
By :
Let's allow the pirate ship to shoot cannonballs by following these steps:
Open the Ship.h file.
Add a read-only property called isShooting, which has an instance variable counterpart called _isShooting, as shown in the following code:
@property (readonly) BOOL isShooting;
Add a cannonball for the left-hand side and the right-hand side of the ship. Both of them are pointers to SPImage, as shown in the following code:
@property SPImage *cannonBallLeft; @property SPImage *cannonBallRight;
Switch to the Ship.m file.
Inside the initWithType method, set the _isShooting instance variable to NO at the top of the method.
Inside the initWithType method, create both cannonballs with the cannonball.png image, set their visible property to NO, and add them to the display tree.
Inside the shoot method, abort if _isShooting is set to YES, else set _isShooting to YES, as shown:
if (_isShooting) {
return;
}
_isShooting = YES;Set some default values for the...
Change the font size
Change margin width
Change background colour