Game Development Reference
In-Depth Information
Then add the new defaultShip method anywhere in the @implementation sec-
tion of the GameLayer class.
-(Ship*) defaultShip
{
CCNode* node = [self getChildByTag:GameSceneNodeTagShip];
NSAssert([node isKindOfClass:[Ship class]], @"node is not a Ship!");
return (Ship*)node;
}
What's left is to stop the ship from automatically shooting bullets all the time. To do
that, open the Ship implementation file and comment out or remove the shootBul-
letFromShip line in the update method:
-(void) update:(ccTime)delta
{
// Shooting is relayed to the game scene
//[[GameLayer sharedGameLayer] shootBulletFromShip:self];
}
Now you can shoot bullets on demand whenever you press or hold the fire button. If
you tap the button repeatedly in quick succession, you should be able to shoot bullets
more rapidly.
Controlling the Action
You can't fly a ship without some form of input. This is where SneakyJoystick
lends a helping hand, I mean, a helping virtual thumbstick. For the joystick, go right
ahead and create a skinned one in the addJoystick method in Listing 7-13 . You
should add this method to the InputLayer class.
Listing 7-13. Adding a Skinned Joystick
-(void) addJoystick
{
float stickRadius = 50;
 
 
Search Nedrilad ::




Custom Search