Reputation: 689
I have instructions in my GameScene for my game and once the instructions are done and I press on a button to go to the GamePlay Scene I would like the GameScene to not show up ever again when I open my app again. I would like the GamePlay Scene to show up the next time I open the app and the GameScene to be removed forever. Is that possible to do in Swift? I tried to do it but it didnt work for me, here is the code I used:
class GameScene: SKScene, {
let deleteInstuctions = NSUserDefaults().boolForKey("delete")
override func didMoveToView(view: SKView) {
if deleteInstuctions {
GameScene.removeFromParent()
NSUserDefaults().setBool(true, forKey: "delete")
NSUserDefaults.standardUserDefaults().synchronize()
}
if node.name == "start" {
NSUserDefaults().setBool(true, forKey: "delete")
//go to gameplay
let goToHome = GamePlay(size: self.size)
let transitionToHome = SKTransition.fadeWithDuration(1.0)
goToHome.scaleMode = SKSceneScaleMode.AspectFill
self.scene!.view?.presentScene(goToHome, transition: transitionToHome)
}
}
}
Upvotes: 0
Views: 29
Reputation: 449
Just use NSUserDefaults to store whether or not the instruction scene has had its button clicked in a Bool. Then on your initial scene, just use an if else statement to load the appropriate scene. I would say this is more basic logic rather than something Swift specific.
In the code you posted, I'm not sure removing GameScene from within itself is a good solution, when you could just choose not to load that scene in the first place if its not needed.
Upvotes: 1