Now, open MenuScene
. First, define the GameScene
reference inside the MenuScene
class, before the init code block:
var gameScene : GameScene? Add the following code below update function override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { for touch: AnyObject in touches { let location = touch.locationInNode(self) let node = self.nodeAtPoint(location) if node.name == PlayButton.name { goToGameScene() } } } func goToGameScene(){ let transitionEffect = SKTransition.flipHorizontalWithDuration(1.0) gameScene = GameScene(size: self.size) gameScene!.anchorPoint = CGPoint(x: 0.5, y: 0.5) self.view?.presentScene(gameScene , transition:transitionEffect) }
Inside didMoveToView
, place the following line just under addChildToScene
:
PlayButton.name = "PLAY"
If you run it now, you will see our menu scene with a play button and a background; if you click outside the play button, nothing will happen. When you click on...