Game Development Reference
In-Depth Information
press the button a shot is guaranteed to be fired. Tap the button quickly, and you should
be able to shoot more bullets than with continuous fire.
You have to make a few minor changes in order to have the ship shoot bullets when
pressing the fire button. Add the declaration of the defaultShip method to the
GameLayer interface as well as the GameSceneNodeTagShip enum:
typedef enum
GameSceneNodeTagBullet = 1,
} GameSceneNodeTags;
@interface GameLayer : CCLayer
NSUInteger nextInactiveBullet;
+(id) scene;
+(GameLayer*) sharedGameLayer;
-(CCSpriteBatchNode*) bulletSpriteBatch;
-(void) shootBulletFromShip:(Ship*)ship;
-(Ship*) defaultShip;
In the implementation file of GameLayer , find the lines where the ship class is cre-
ated in the init method and assign the ship the GameSceneNodeTagShip tag so
that it's easily accessed later on. Alternatively you can also use an instance variable to
store the reference to the ship object.
// add the ship
Ship* ship = [Ship ship];
ship.position = CGPointMake(80, screenSize.height / 2);
ship.tag = GameSceneNodeTagShip;
[self addChild:ship z:10];
Search Nedrilad ::

Custom Search