Cocos2d-X development of Chinese chess thirteen to achieve the return and use xml to achieve Chinese, cocos2d-x thirteen

Source: Internet
Author: User

Cocos2d-X development of Chinese chess thirteen to achieve the return and use xml to achieve Chinese, cocos2d-x thirteen

In the previous section, the game results are displayed and hidden. This blog will return to the game's start scenario and display Chinese characters using xml.

Before writing the code, let's take a look at


Implementation Code:
Add the following code to the member function init () under SceneGame to create a return button.

// Create Return BUTTON CCMenuItem * itemReturn = CCMenuItemImage: create ("return.png", "return.png", this, menu_selector (SceneGame: Return )); menu-> addChild (itemReturn); itemReturn-> setPositionX (itemStart-> getPositionX (); itemReturn-> setPositionY (itemStart-> getPositionY () -60-60-60-60-60); itemReturn-> setScale (0.2f );

After the Return button of the scenario, a menu response function void Return (CCObject *) is used. Therefore, you need to declare void Return (CCObject *) in SceneGame, and finally void Return (CCObject *) the code in is as follows:

/Return to the start scene void SceneGame: Return (CCObject *) {// Return to the start scene CCDirector: sharedDirector ()-> replaceScene (SceneStart: scene ());}

Display Chinese characters in the game:


Implementation Code:
In the project directory, the Resource folder contains an xml file named Name with the extension of. plist.

Add the following code to Name. plist:

<? Xml version = "1.0" encoding = "UTF-8"?> <! DOCTYPE plist PUBLIC "-// Apple Computer // dtd plist 1.0 // EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version = "1.0"> <dict> <key> voice </key> <string> background music </string> <key> return </key> <string> return </string> </dict> </plist>

Add the following code to init () under SceneGame.

Char Voice [256]; char Return [256]; // create a dictionary class to read the xml file CCDictionary * dict = CCDictionary: createWithContentsOfFile ("Name. plist "); // from infmation. plist reads the background music name const CCString * voice = dict-> valueForKey ("voice"); sprintf (Voice, "% s", voice-> getCString ()); // from Name. in plist, the return name const CCString * r = dict-> valueForKey ("Return"); sprintf (return, "% s", r-> getCString ()); // create a label and display the text "CCLabelTTF * label = CCLabelTTF: create (Voice," Arial ", 25); addChild (label ); // set the text position label-> setPosition (ccp (winSize. width/2 + 110, winSize. height/2-120); // set the text color label-> setColor (ccc3 (0, 0, 0); // create a label, display the text CCLabelTTF * label1 = CCLabelTTF: create (Return, "Arial", 25); addChild (label1); // set the text position label1-> setPosition (ccp (winSize. width/2 + 120, winSize. height/2-180); // set the text color label1-> setColor (ccc3 (0, 0, 0 ));
 

Zookeeper

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.