Saving Sprite Dial Level Data

There is a project I'm working on, in which a set of goals appears on the screen. Goals should be displayed in a certain amount at the same time and with some delay between each appearance. My question is how to properly store level data for this game. I have considered using a csv file to store level data (target type, location, delay, etc.), but I am wondering if there is a better way to do this. I also thought about creating a level object to store level information, but I'm not sure. Apple says it uses Sprite Node Archives, but I can't understand what that means. Any suggestions?

+4
source share
1 answer

Have you thought about using a plist file? This would be the easiest to parse. You can have an array of goals (dictionaries), and then determine the position, the absolute delay, and whatever you want.

enter image description here

Then just read it in the array:

NSArray *targets = [NSArray arrayWithContentsOfFile:plistPath];
for (NSDictionary *dictionary in targets) {
    CGPoint position = CGPointMake([dictionary[@"positionX"] floatValue], 
                                   [dictionary[@"positionY"] floatValue]);
    float delay = [dictionary[@"time"] floatValue];
    // Do something with this information, maybe create a Target instance etc.
}

You can also do the same with CSV files, but it would be a little harder to parse (not too hard).

As for archives, Apple means that all Sprite Kit classes support NSCoding. This means that they can be archived to a file (or an NSData object) and then not archived from this archive. This, however, is different from what you want to do. Archiving would create one β€œsnapshot” of the current state of the game. Therefore, it would be nice to save the game, for example, when the user leaves.

+5

All Articles