Last active
July 1, 2016 21:03
-
-
Save veeneck/1d988af6e20e67b131c9cf775f546f16 to your computer and use it in GitHub Desktop.
Example usage of saving GameData
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// User clicks on slot one, so we want to create a new save file for that slot | |
if GameData.sharedInstance.loadGame(saveFile: "One") { | |
/// An existing save file was there, progress as you need to | |
} | |
else { | |
/// A new save file was created, so start your game from a fresh state | |
} | |
/// User buys 100 gold | |
GameData.sharedInstance.bank += 100 | |
GameData.sharedInstance.save() | |
/// User advances to level 2, so you want to update level data and save the file | |
/// Assumes you have handle on Level object already | |
level.completed = true | |
/// Then, I just replace the entire instance of the storage with the new level object. | |
/// More important when working with structs | |
GameData.sharedInstance.levelData?.levels[level.id] = level | |
/// Call save to write the changes out | |
GameData.sharedInstance.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment