To abort the current game, we need to follow these steps:
Open the
Battlefield.m
file.Inside the initializer, we should add the abort button right after the resume button:
SPButton *buttonAbort = [SPButton buttonWithUpState:[[Assets textureAtlas:@"ui.xml"] textureByName:@"button_abort"]];
Position the abort button in the bottom-right corner:
buttonAbort.x = Sparrow.stage.width - buttonAbort.width - 4.0f; buttonAbort.y = Sparrow.stage.height - buttonAbort.height - 4.0f;
Import the
SceneDirector
class, as shown in the following line of code:#import "SceneDirector.h"
Add a listener to the abort button using a block, as shown in the following code:
[buttonAbort addEventListenerForType:SP_EVENT_TYPE_TRIGGERED block:^(SPEvent *event) { [((SceneDirector *) self.director) showScene:@"piratecove"]; }];
Add the button to the display tree, as shown in the following code:
[self addChild:buttonAbort];