Game Development Reference
In-Depth Information
tryAgainTextNodeLine1.verticalAlignmentMode =
SKLabelVerticalAlignmentMode.Center
tryAgainTextNodeLine1.fontSize = 20
tryAgainTextNodeLine1.fontColor
= SKColor.whiteColor()
tryAgainTextNodeLine1.position
= CGPointMake(size.width / 2.0, 100.0)
addChild(tryAgainTextNodeLine1)
let tryAgainTextNodeLine2 = SKLabelNode(fontNamed:
"Copperplate")
tryAgainTextNodeLine2.text = "TO PLAY AGAIN!"
tryAgainTextNodeLine2.horizontalAlignmentMode =
SKLabelHorizontalAlignmentMode.Center
tryAgainTextNodeLine2.verticalAlignmentMode =
SKLabelVerticalAlignmentMode.Center
tryAgainTextNodeLine2.fontSize = 20
tryAgainTextNodeLine2.fontColor
= SKColor.whiteColor()
tryAgainTextNodeLine2.position
= CGPointMake(size.width / 2.0,
tryAgainTextNodeLine1.position.y - 40.0)
addChild(tryAgainTextNodeLine2)
}
}
As you look at this new file, you will see that the second
init()
method takes three
parameters: the
size
of the scene, the result of the game as a
Bool
, and the player's
score. The
size
parameter, as you know, is used to set the size of the scene, and the third
and fourth parameters will be used to display information about the result of the game to
the user.
Inside the
init()
method, it starts off by adding a background image. The image used is
the same image you used in the
GameScene
. After that, it adds several labels to the
scene, including two labels that are added to the middle of the scene. The first tells the
user whether they won or lost the game, and the second tells them their score. Next, two
labels are added to the bottom of the scene telling the player to tap the screen anywhere to
play again. Once you have added the code to the
MenuScene.swift
file, save your
work, and let's go back to the
GameScene.swift
file.