Game Development Reference
In-Depth Information
This time when you run the game, you will notice the timer start running when you touch
the device, as in Figure 15-2 .
Figure 15-2 . Timer running
The last thing you need to do for the timer is to call the stopTimer() method when you
find the enemy. The best place for this will be in the SCNPhysicsWorld didBeginContact
protocol. Find the section in your GameViewController class and replace the
println("Enemy found") with the following:
gameOverlay.stopTImer()
This time when you run the game and maneuver the spaceman to the enemy, the timer will
stop, and you will have the time it took you to find him.
“Game Over” Screen
You have a working game now, but wouldn't it be nice to have a “game over” screen to
show your time and be able to restart the game? You will create another view that will up-
date the sceneView.overlaySKScene when the spaceman finds the enemy.
Create a new Swift file called GameOverView.swift just like you have created in the past.
The GameOverView will look familiar; Listing 15-6 has the code you need to put into the
GameOverView class.
Listing 15-6 . GameOverView
Search WWH ::




Custom Search