Game Development Reference
In-Depth Information
You will get the node that you named timer in the start function and then stop the action
timerAction
.
Listing 15-4
.
GameOverlay.stopTimer
func stopTimer() {
var timerNode = childNodeWithName("timer") as
SKLabelNode
timerNode.removeActionForKey("timerAction")
}
You have your
GameOverlay
class completed, so now you will need to update the
GameViewController
to use this class and place it over your 3D Scene Kit scene.
Hooking Up the Controller to the Overlay
You have the
GameOverlay
class complete, so now it's time to connect it to the
GameViewController
. First you will want to create a class-level variable that you will use
to get access to the
GameOverlay
class. Doing this, you will easily be able to call the
methods to start the timer.
var gameOverlay: GameOverlay!
In the
GameViewController viewDidLoad
function, you will need to add this
GameOver-
lay
to the
SCNScene
. Doing this will allow the Scene Kit framework to overlay your
GameOverlay
onto the current scene.
sceneView.overlaySKScene = GameOverlay(size:view.frame.size)
gameOverlay = sceneView.overlaySKScene as GameOverlay
Right now is a good time to run your game and see the overlay timer on top of the scene
you have been working on. Once you run the game, you should have a scene similar to