saving/reading level data using plists
I have very simple data for each level.
stuff like some numbers, and the names of sprite files and backgrounds.
1)I'd like to read them off a plist file.
2)I'd also like to create the plist file separately from the code. Is there an editor?
How can I do the two things above?
Thanks!
stuff like some numbers, and the names of sprite files and backgrounds.
1)I'd like to read them off a plist file.
2)I'd also like to create the plist file separately from the code. Is there an editor?
How can I do the two things above?
Thanks!
You can create and edit plists using the Property List Editor, which comes with the developer tools: /Developer/Applications/Utilities/Property List Editor
You can load your plist with something like this:
... and presto, you have a dictionary of all your level data right there. Pretty simple huh?
You can load your plist with something like this:
Code:
NSDictionary *myDictionary = [[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"MyLevel1Data" ofType:@"plist"]] retain];... and presto, you have a dictionary of all your level data right there. Pretty simple huh?
Thanks AnotherJake!
Is there a way to add my own classes to the plist?
Is there a way to add my own classes to the plist?
You mean, actual compilable code? Not really, no -- at least not in any practical sense.
Why? What did you have in mind?
Why? What did you have in mind?
NSCoding might serve your purpose, though making classes NSCoding compliant can be a bit tedious.
While I probably don't have the most efficient method of implementing Coder support, I know that mine actually works. Perhaps it (or something similar) will give you the inspiration to implement something that works well for you:
https://github.com/fsdev-cmiller/Outpost...Type.m#L37
While I probably don't have the most efficient method of implementing Coder support, I know that mine actually works. Perhaps it (or something similar) will give you the inspiration to implement something that works well for you:
https://github.com/fsdev-cmiller/Outpost...Type.m#L37
Ha! I totally mis-read aerospaceman's post!
thanks cmiller
I think I'll stick with a simple plist per Jake's suggestion. my level data is not very complex and i don't mind calling each basic variable separately.
I think I'll stick with a simple plist per Jake's suggestion. my level data is not very complex and i don't mind calling each basic variable separately.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Saving context | markhula | 4 | 5,357 |
Mar 8, 2011 02:37 AM Last Post: markhula |
|
| Level data structure | tfifriday | 3 | 2,738 |
Jan 9, 2009 02:30 PM Last Post: ThemsAllTook |
|

