I need to make a segue from a GameScene to a UIViewController. My code so far is the following:
In the GameViewController.swift I added:
if let view = self.view as! SKView? {
if let scene = SKScene(fileNamed: "GameScene") {
scene.scaleMode = .aspectFill
scene.viewController = self
view.presentScene(scene)
}
...
and in my GameScene.swift I added
class GameScene: SKScene, SKPhysicsContactDelegate {
var viewController: UIViewController?
...
as well as
func returnToMainMenu(){
self.viewController.performSegueWithIdentifier("push", sender: viewController)
}
So my problem is that when I state - scene.viewController = self - I get an error that says "value of type 'SKScene' has no member 'viewController'". What can I do to fix this?
The problem is that the
viewController
property is declared inGameScene
, but when the scene is created it is of typeSKScene
. The simple way to fix it would be to initialise the scene as aGameScene
then you will have access to the members declared inGameScene
.Also, you should try an exit seque when returning to main menu, but that's another topic.