Cocos2d-x v3.0 official edition early adopters experience Label text labels

Source: Internet
Author: User

Cocos2d-x has added a new Label API in the new version, and the difference is that 2. in Version x, three different classes are used to create different text labels. However, the Creation Method of the genie is imitated. A Class creates different forms of text, however, the core content is similar.

 

This is the new Label class structure.

 

In the 2.x series, there are three types of texts: TTF, BMFont, and Atlas. In 3.0, the TTF is split into two types. Let's take a look at the creation of these four types of text.

1. Label: createWithTTF

This is how to create a text file in ttf format.

 

TTFConfig config("fonts/Marker Felt.ttf", 25);auto label1 = Label::createWithTTF(config, "Hello Cocos2d-x");label1->setPosition(Point(size.width/2, size.height*0.8));addChild(label1);

2. Label: createWithSystemFont

 

This is created using the built-in font, which is similar to TTF in 2.x.

 

auto label2 = Label::createWithSystemFont("Hello Cocos2d-x", "Consolas", 25);label2->setPosition(Point(size.width / 2, size.height*0.6));addChild(label2);

 

 

Note that the first parameter is the text content to be displayed, and the second parameter is the system font.

 

3. Label: createWithBMFont

Create text using static font files to generate fnt files and corresponding png Images

 

auto label3 = Label::createWithBMFont("fonts/helvetica-32.fnt", "Hello Cocos2d-x");label3->setPosition(Point(size.width / 2, size.height*0.4));addChild(label3);

4. Label: createWithCharMap

 

This corresponds to the creation of Atlas in 2.x. However, there are two ways to match the text in the image. One is to directly set the width and height of each font to be obtained, and the other is to use the fnt file, but the principles are the same.

 

auto label4 = Label::createWithCharMap("fonts/tuffy_bold_italic-charmap.plist");label4->setPosition(Point(size.width / 2, size.height*0.2));addChild(label4);label4->setString("Cocos2d-x");auto label4 = Label::createWithCharMap("fonts/tuffy_bold_italic-charmap.png", 48, 66, ' ');label4->setPosition(Point(size.width / 2, size.height*0.2));addChild(label4);label4->setString("Cocos2d-x");

The text effects created in the above four forms.

 

 

In addition, there are some alignment parameters in other overload forms of the create FUNCTION, which will not be described here. Besides the different writing forms, the results are the same.
 

 

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.