jeudi 26 mars 2015

Am I loading ViewController over ViewController

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

}
}



Aucun commentaire:

Enregistrer un commentaire