1
votes

Hi I have a spriteKit game set up where everytime the user dies Ill get a pop up ViewController with Try again button and some iAds set up.

I have a segue to the viewController and an unwind segue from the VC to the gameViewController.

When I call the unwind func I reinitialize the scene for different reasons. My question is, am I creating view over view which will eventually lead to a crash or am I correctly reinitializing the scene. I took the code from viewDidLoad and put it into a function called "setUp()" and I call that function from the unwindSegue.

check it out: (all in GameViewController)

  var currentLevel: Int!
var gameScene = GameScene()

override func viewDidLoad() {
    super.viewDidLoad()

    currentLevel = gameScene.currentLevel
    setUp()


}
 @IBAction func perpareForUnwind(unwindSegue: UIStoryboardSegue) {
    setUp()
}

func setUp() {

    if let scene = GameScene.level(currentLevel) {
        // Configure the view.
        let skView = self.view as SKView
        skView.showsFPS = true
        skView.showsNodeCount = true

        /* Sprite Kit applies additional optimizations to improve rendering performance */
        skView.ignoresSiblingOrder = true

        /* Set the scale mode to scale to fit the window */
        scene.scaleMode = .AspectFill

        skView.presentScene(scene)

        scene.viewController = self

    }
}
1

1 Answers

0
votes

You are not creating a new view controller if you are using the unwind segue correctly. From what it looks like that is the case. If you are still not confident you can log out println(\(self)) and make sure of it (My swift is rusty but I think that is how you log it out).

Your question title asks about view controllers but your question info asks about creating additional views. This isn't an issue either. When you do

let skView = self.view as SKView

You are getting the current view of the view controller and just casting it as an SKView. You are not recreating another view at all.

Hopefully that helps.