Game Development Reference
In-Depth Information
{
HelloWorldString = " Hello Kobold2D!",
HelloWorldFontName = " Marker Felt",
HelloWorldFontSize = 50,
},
}
With the exception of the uppercase first letter, these settings match the properties of
the HelloWorldLayer class in name and data type. I'm sure you can see the con-
nection here. Indeed, the KKConfig class method injectProper-
tiesFromKeyPath , shown in Listing 16-3, loads the values from the Hel-
loWorldSettings subtable and injects them into the correspondingly named prop-
erties of the target class, in this case self .
Listing 16-3 . Injecting (Assigning) the Custom Settings to Class Properties
[KKConfig injectPropertiesFromKeyPath:@"HelloWorldSettings" target:self];
By inject I mean if there is a Lua table named HelloWorldSettings , then each
setting it contains will be assigned to a correspondingly named property of the target
class, in this case self . For example, the setting HelloWorldString will be as-
signed to the class property helloWorldString if it has the correct data type
( NSString* ) and isn't set to be a readonly property.
Tip By using KKConfig , you can easily make your app data-driven, which
for example allows designers and artists to tweak your app's behavior without
having to modify source code. Data-driven development also comes to shine
when you have a variety of game objects with the same or similar settings. You
don't want these settings spread throughout your code—you want to centralize
them in a single file that provides the necessary overview.
After injection, the three properties will contain the same values as the Hel-
loWorldSettings Lua table. They're ready to be used by the label:
CCLabelTTF* label = [CCLabelTTF labelWithString:helloWorldString
fontName:helloWorldFontName
fontSize:helloWorldFontSize];
 
 
Search Nedrilad ::




Custom Search