Game Development Reference
In-Depth Information
Figure 15-1 . Overlay scene with a timer
Now that you have the overlay, you need to start the timer when the user starts to move
the spaceman. Since you will be using the touchCount in the sceneView to start the timer,
you will want to also make sure your player hasn't already started the game; otherwise,
the timer will always reset itself with every touch. After the GameViewController class
definition, you will add another variable that will be used as a flag for when the game
starts, and you will initialize it to false: var gameStarted = false .
Now when your player starts the game, you will set this to true and then back to false at
the end of the game. To accomplish this, you will need to add some logic into the didSim-
ulatePhysicsAtTime function in the GameViewControllerGameViewController .
func renderer(aRenderer: SCNSceneRenderer,
didSimulatePhysicsAtTime time: NSTimeInterval) {
In this function, you will add Listing 15-5 at the top of the function. This will check to see
whether the user has touched the screen and, if so, start the timer and set the gameStarted
flag. You will use this flag later in the code.
Listing 15-5 . Start the Timer in the didSimulatePhysicsAtTime Protocol
if sceneView.touchCount > 0 && !gameStarted {
gameOverlay.startTimer()
gameStarted = true
}
Search WWH ::




Custom Search