Game Development Reference
In-Depth Information
Our Game Over scene
First, we create a new scene as usual. Next, we create a transition object. There are
many kinds of transitions with many different effects. On the third line, we ask view
to present a new scene. This ends our scene lifecycle. Scenes do not get saved in
memory; on each transition the old scheme is destroyed, and if you want to use it
again, you have to make it all over, as shown in the preceding screenshot.
There are many different transition types that you can use, check the
SKTransition class reference for a list of possible transitions. It is
available at https://developer.apple.com/library/IOs/
documentation/SpriteKit/Reference/SKTransition_Ref/
Introduction/Introduction.html or in Xcode search.
In order to call this method, we need to subscribe to notifications and add the
following code to the initWithSize: method of ERGMyScene.m :
[[NSNotificationCenter defaultCenter] addObserver:self selector:@
selector(gameOver) name:@"playerDied" object:nil];
Now we need to make a new scene, a Game Over scene, to show to the player each
time he fails.
Create a new class, name it as ERGGameOverScene , and make it a subclass of
SKScene . Add the following code:
- (instancetype) initWithSize:(CGSize)size
{
self = [super initWithSize:size];
if (self) {
SKLabelNode *node = [[SKLabelNode alloc] initWithFontNamed:@"
Chalkduster"];
node.text = @"Game over";
 
Search WWH ::




Custom Search