Time for action – making the pirate cove playable
To add game mechanics to the pirate cove, use the following steps:
Move the line of code
[SPTextField registerBitmapFontFromFile:@"PirateFont.fnt"];
fromDialog.m
to the beginning of theGame.m
file.Add a button in
PirateCove.m
, as shown in the following code:SPButton *buttonBattle = [SPButton buttonWithUpState:[[Assets textureAtlas:@"ui.xml"] textureByName:@"dialog_yes"]; text:@"Begin battle"]; buttonBattle.y = Sparrow.stage.height - buttonBattle.height - 8.0f; buttonBattle.x = (Sparrow.stage.width - buttonBattle.width) / 2; [buttonBattle addEventListenerForType:SP_EVENT_TYPE_TRIGGERED block:^(SPEvent *event){ [((SceneDirector *) self.director) showScene:@"battlefield"]; }];
Add the button to the display tree using the following line of code:
[self addChild:buttonBattle];
In the following code, we add a text field to display the current amount of gold, which needs to be declared as an instance variable first:
_goldTextField = [SPTextField...