0

I have a game, breakout clone basically. I got tired of making levels programmatically so I got this editor = Scenedesigner that lets you put sprites, nodes, etc on screen.

Question - how do I load that .plist file in my game and make my game understand it?

For example, I use composite objects for my sprites - for example ball is of Ball class that contains ccsprite as property, how will that work?

Dvole
  • 5,725
  • 10
  • 54
  • 87

2 Answers2

1

Not sure about how you created your plist, but this post about using NSDictionary should should answer your question: https://stackoverflow.com/a/1760384/388412

...it's basically the same for NSArray, both classes can store objects and read from and write to file/URL (thus reading and writing plists).

So, you probably should have rather started with a dictionary or array and write that to file to create a plist. As the other way round might cause problems depending on the format of your specific plist.

As for more complex serialization, you should look into the NSCoding protocol. With that you can serialize and deserialize whole object trees (using NSArchiver and NSUnarchiver). Though, don't use NSArchiver/NSUnarchiver separately, better make your classes NSCoding compliant.

If your case is less complex, I recommend starting with NSDictionary / NSArray serialization as it's a bit easier to handle.

Community
  • 1
  • 1
auco
  • 9,329
  • 4
  • 47
  • 54
0

You can use dictionaryWithContentsOfFile method of NSDictionary and
arrayWithContentsOfFile method of NSArray to convert your plist into the array or dictionary depending upon the content of plist.

Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184