Wiring up the START GAME button
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 Start button. The game should switch to the GameScene
class, and gameplay will begin. Congratulations, you have successfully implemented...