Return from GameScene

Hi team , I’m trying to implement a code to back to homescreen from a game scene , I created a main view, after clicking in a button my game starts , but when the game finish my intention is go back to homeScreen… I got an error , someone can help on that ?

override func touchesBegan(touches: Set, withEvent event: UIEvent?) {

    if gameState == .GameOver {
        let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let home = mainStoryboard.instantiateViewControllerWithIdentifier("HomeScreenViewController")
        self.view!.window?.rootViewController?.presentViewController(home, animated: true, completion: nil)

// restartGame()
}
}

It depends on how your game screen is presented. If using a Navigation Controller, the Back button is built in (but that’s probably not what you want in your game). If using presentViewController then your presentation is modal (probably what you want) and you should dismiss the presented view controller with dismissViewControllerAnimated.

What you don’t want to be doing is creating another home view controller and then presenting that…

thanks , I will try …:grinning: