How to create entries in the info.plist file for settings for colors saved in specific game levels?

263 Views Asked by At

I am trying to write a game that has several levels. Each level will have its own settings, including several UIColor-based values. I would like to use the easiest way to create these settings, and methinks that would be using the info.plist file. Is there a way to write the plist.info file and create entries for [UIColor redColor] and [UIColor blueColor] for example? Or would I have hard code that into my levels somehow? (seems like that would be silly).

Would love any input.

2

There are 2 best solutions below

0
On

Plists can't store color objects. You can store strings, like "purple" or "red", and then manually map those out in code to color objects.

You can also check out something similar: https://github.com/quartermaster/DB5

0
On

Bit late but this should do what you want...

  1. create a plist containing a list of strings e.g. @"redColor", @"blueColor", @"greenColor"

  2. read those strings back in to an array

  3. then access them with the following lines...

    NSString *colourname = [self.colourArray objectAtIndex:row];

    SEL colourselector = NSSelectorFromString(colourname);

    if( [UIColor respondsToSelector:colourselector] ) [UIColor performSelector:colourselector];