1

So I'm working on a game for iOS using Swift 3 and SpriteKit, and I am stuck at a point because every time you close the app you loose what level you were on. So as stated in the title how do you save level data in Swift 3 using SpriteKit ( As also stated I am not using storyboards and instead using Sprite kit scenes ) Here the code in my game view controller.

import UIKit
import SpriteKit

class GameViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        if let scene = GameScene(fileNamed:"GameScene")

        {
            // Configure the view.
            let skView = self.view as! SKView
            skView.showsFPS = false
            skView.showsNodeCount = false

            /* 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)

        }
    }
    override var shouldAutorotate : Bool {
        return true
    }

    override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
        if UIDevice.current.userInterfaceIdiom == .phone {
            return .allButUpsideDown
        } else {
            return .all
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Release any cached data, images, etc that aren't in use.
    }

    override var prefersStatusBarHidden : Bool {
        return true
    }
}
Rajat
  • 10,977
  • 3
  • 38
  • 55
  • 1
    Many ways. An easiest would be to save data into user defaults. – Whirlwind Nov 30 '16 at 17:59
  • 1
    You can start here : http://stackoverflow.com/a/40437047/3402095 It is an example of how to store [String] into defaults, but similar logic (and syntax) can be applied to simple types, objects, dictionaries etc. – Whirlwind Nov 30 '16 at 22:17

0 Answers0