September 2018
Intermediate to advanced
434 pages
8h 47m
English
Just like in GameScene, we will add a touchesBegan function to the MenuScene class to capture touches on the START GAME button. To implement touchesBegan, open MenuScene.swift and, at the bottom of the class, add a new function named touchesBegan, as shown here:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in (touches) {
// Find the location of the touch:
let location = touch.location(in: self)
// Locate the node at this location:
let nodeTouched = atPoint(location)
if nodeTouched.name == "StartBtn" {
// Player touched the start text or button node
// Switch to an instance of the GameScene:
self.view?.presentScene(GameScene(size: self.size))
}
}
} Run the project and tap the ...
Read now
Unlock full access