Search code examples
swiftsavelevels

SpriteKit Swift best way to save level data


I am making a new game that will have about 4 worlds with 7-8 levels each, so about 30 levels in total. I am trying to figure out a way to save data such as highScores, unlockStatus, best time etc for each of them.

The best way I have found so far is to make 1 GameData class with the NSCoding format for each world that than saves the level data. It works fine but it still seems very clunky and a lot of code as I have 4 GameData classes now and in each I still need create properties like highScores etc for each level. Lets not even talk about iCloud key value storage.

How would a game like the new Angry Birds 2 save and keep track of its game data for 240 plus levels? Surely they do not create 240 properties for highScores etc.

Could someone please steer me in the right direction. Thank you for any help and suggestions


Solution

  • Old question but I might as well post an answer.

    I ended up going with arrays, dictionaries and arrays of dictionaries. This way I can save multiple levels without much hassle. It also very easy to now loop through those dicts/arrays do do things such as level unlocks.

    See this more recent question for sample code

    Is there a better way to save a custom class to NSUserDefaults than encoding and decoding everything with NSCoder?