Cocos2d-x text rendering

Source: Internet
Author: User

Text rendering:

The CCLabelAtlas, CCLabelBMFont, and CCLabelTTF classes inherit the CCLabelProtocol class, that is, you can use system words or customize the rendering font.

The CCLabelAtlas class uses images as a text method and can be directly defined through images.

CCLabelAtlas * label0 = CCLabelAtlas: create ("ASDE test", "tuffy_bold_italic-charmap.png", 46, 64, ''); // Parameter order: to display characters, image paths, character width, character height, starting character label0-> setPosition (ccp (100,200); label0-> setOpacity (200); this-> addChild (label0 ); CCLabelAtlas * label2 = CCLabelAtlas: create ("456789123", "tuffy_bold_italic-charmap.png", 46, 64, ''); label2-> setPosition (ccp (visibleSize. width/2, visibleSize. height/2); label2-> setOpacity (200); this-> addChild (label2); // CCActionInterval * ac = CCFadeOut: create (1.2f ); CCActionInterval * ac2 = ac-> reverse (); label2-> runAction (CCRepeatForever: create (CCSequence: create (ac, ac2, NULL ))); // use the description of the plist configuration file. You can modify the configuration file information as needed, including the image path, character width and height, and the starting character "CCLabelAtlas * label1 = CCLabelAtlas :: create ("wer vbn ",". /tuffy_bold_italic-charmap.plist "); // Parameter order: to display characters, plist file path label1-> setPosition (ccp (10,100); label1-> setOpacity (200 ); this-> addChild (label1 );


The CCLabelTTF class implements font labels through system words.

CCLabelTTF * ttf = CCLabelTTF: create ("hello world", "Helvetica", 30, ccp (320, 30), kCCTextAlignmentLeft); // Parameter order: to display characters, font Name, font size, range size, alignment mode [kCCTextAlignmentLeft (left alignment) kCCTextAlignmentCenter (center aligment)] ttf-> setPosition (ccp (300,400 )); this-> addChild (ttf );


The CCTextFieldTTF class input box uses a text tag to inherit the CCLabelTTF class.

CCTextFieldTTF *pTest = CCTextFieldTTF::textFieldWithPlaceHolder("
 
  ", "STHeitiTC-Light",40 );pTest->setPosition(ccp(300, 500));this->addChild(pTest);
 


Each word in the CCLabelBMFont class is an genie. Each word can define an action and supports FNT files.

CCLabelBMFont * label = CCLabelBMFont: create ("Bitmap Font Atlas Xub", "fonts/bitmapFontTest. fnt "); addChild (label); CCSize s = CCDirector: sharedDirector ()-> getWinSize (); label-> setPosition (ccp (s. width/2-200, s. height/2); label-> setAnchorPoint (ccp (0.5f, 0.5f); CCSprite * BChar = (CCSprite *) label-> getChildByTag (0 ); // obtain the 1st character 'B' CCSprite * FChar = (CCSprite *) label-> getChildByTag (7); // obtain the 7th character 'F' CCSprite * AChar = (CCSprite *) label-> getChildByTag (12); // obtain the 12th character 'a' CCSprite * XChar = (CCSprite *) label-> getChildByTag (18 ); // obtain the 12th character 'a' // create action for the character CCActionInterval * rotate = CCRotateBy: create (2,360); CCAction * rot_4ever = CCRepeatForever: create (rotate ); CCActionInterval * scale = CCScaleBy: create (2, 1.5f); CCActionInterval * scale_back = scale-> reverse (); CCSequence * scale_seq = CCSequence: create (scale, scale_back, NULL); CCAction * scale_4ever = CCRepeatForever: create (scale_seq); CCActionInterval * jump = CCJumpBy: create (0.5f, CCPointZero, 60, 1); CCAction * jump_4ever = cursor :: create (jump); CCActionInterval * fade_out = CCFadeOut: create (1); CCActionInterval * fade_in = CCFadeIn: create (1); CCSequence * seq = CCSequence: create (fade_out, fade_in, NULL); CCAction * fade_4ever = CCRepeatForever: create (seq); CCActionInterval * by = CCMoveBy: create (1.0f, ccp (300,300 )); CCActionInterval * by2 = by-> reverse (); CCSequence * seq_by = CCSequence: create (by, by2, NULL); CCAction * ac_by = CCRepeatForever: create (seq_by ); BChar-> runAction (rot_4ever); BChar-> runAction (scale_4ever); FChar-> runAction (jump_4ever); AChar-> runAction (fade_4ever); XChar-> runAction (ac_by );


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.