1

I know this question has been asked many times, however most aren't properly answered and do not follow the same set up as mine. I have two UIViewControllers, GameViewController and MenuViewController. The MenuViewController uses a storyboard and UIKit. The GameViewController loads an SKScene. When the app starts it opens the MenuViewController. I have already made a button that segues to the Game on the Menu in the storybaord. That works, but now I am trying to do the opposite and return back to the Menu while in the Game. I have tried to use code that has answered similar questions but none seems to work.

Here is my GameViewController that I messed around with:

class GameViewController: UIViewController {
override func viewDidLoad() {
    super.viewDidLoad()
    if let view = self.view as! SKView?{
        if let scene = SKScene(fileNamed: "GameScene"){
    let gameScene = scene as! GameScene
    gameScene.gameViewControllerDelegate = self
    gameScene.scaleMode = .aspectFill
    view.presentScene(gameScene)
        }
    view.showsFPS = true
    view.showsNodeCount = true
    view.ignoresSiblingOrder = true
        // Do any additional setup aft)er loading the view.
        }
    }
func callMethod(inputProperty:String){
    print("inputProperty is: ",inputProperty)
}

And the code I added to my GameScene:

class GameScene: SKScene, SKPhysicsContactDelegate {
weak var gameViewControllerDelegate:GameViewControllerDelegate?


override func didMove(to view: SKView) {
    gameViewControllerDelegate?.callMethod(inputProperty: "call game view controller method")
Whirlwind
  • 14,286
  • 11
  • 68
  • 157
Carter Grycko
  • 93
  • 1
  • 7
  • Is there any particular reason for having two view controllers? In Sprite-Kit, usually, you have one view controller, and multiple scenes. That way, you use SKTransitions to make transition between scenes, which is, I guess, how it is meant to be (or that is just what I find as most comfortable way of making transitions :). But if you decide to try it, read this : http://stackoverflow.com/a/35409586/3402095 – Whirlwind Mar 12 '17 at 22:16
  • @Whirlwind I believe I read in tutorial or somewhere that that was the way to do it. That question you linked uses swift 2. Would combining the two view controllers be possible? – Carter Grycko Mar 12 '17 at 23:11

0 Answers0