Game Development Reference
In-Depth Information
You now have a scene to transition to, so let's add the code to perform the transition. The
code to make this transition is shown in the following snippet:
let transition = SKTransition.crossFadeWithDuration(2.0)
let menuScene = MenuScene(size: size,
gameResult: gameResult,
score: score)
view?.presentScene(menuScene, transition: transition)
The first line of this snippet creates a cross-fade transition that will fade in the scene over
a two-second duration. The second line creates the MenuScene itself, passing it the size
of the current scene followed by the result of the game and the player's score. The third
line of this snippet actually presents the MenuScene , which replaces the current scene,
using the transition created on the first line. After reading this code, add it to the bottom of
the GameScene 's gameOverWithResult() method, as shown here:
func gameOverWithResult(gameResult: Bool) {
playerNode!.removeFromParent()
playerNode = nil
let transition = SKTransition.crossFadeWithDuration(2.0)
let menuScene = MenuScene(size: size,
gameResult: gameResult,
score: score)
view?.presentScene(menuScene, transition: transition)
}
Now run the game and either play to win or play to lose. Either way, you will see the new
scene fade in, as shown in Figure 8-2 , when the game is over.
Search WWH ::




Custom Search