Strings. plist is placed in the Project Resource Directory (save as a UTF-8) with the following content:
<? XML version = "1.0" encoding = "UTF-8"?> <! Doctype plist public "-// Apple // DTD plist 1.0 // en" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version = "1.0"> <dict> <key> data </key> <dict> <key> Hello </key> <string> perfect world, perfect Life </string> <key> cocos2d. x. display_fps </key> <true/> <key> cocos2d. x. GL. projection </key> <string> 3D </string> <key> cocos2d. x. texture. pixel_format_for_png </key> <string> rgba8888 </string> <key> cocos2d. x. texture. pvrv2_has_alpha_premultiplied </key> <false/> </dict> <key> metadata </key> <dict> <key> Format </key> <integer> 1 </Integer> </dict> </plist>
After that we need to call the following code for initialization before generating our own cocos2d-x project director class instance:
CCConfiguration::sharedConfiguration()->loadConfigFile("config/strings.plist");
Generally, this operation is performed at the beginning of appdelegate: applicationdidfinishlaunching. Then you can use the content in the configuration file in the program:
Ccconfiguration * conf = ccconfiguration: sharedconfiguration ();
Const char * hellostr = conf-> getcstring ("hello", "unknown ");
Cclabelttf * plabel = cclabelttf: Create (hellostr, "Arial", 24 );
Plabel-> setposition (CCP (200,200 ));
This-> addchild (plabel, 1 );
Cocos2d-x Chinese garbled Problem