[Cocos2d-x]-detailed description of cclabelprotocol text labels

Source: Internet
Author: User

Cocos2d-x learning exchange group: 140326755

Email:Hahayacoder@gmail.com

 

 

1 cclabelprotocol is the parent class of text labels, cclabelprotocol has three direct subclasses, are used to create text labels in the cocos2d-x, the following is the class structure diagram

 

2
Cclabelttf is not only a subclass of cclabelprotocol, but also a subclass of ccsprite. cclabelttf is used to render text labels. You can specify the font. Each time you set the string content, you need to recreate the texture and rendering, poor performance (you can view the relevant source code), so we usually use cclabelatlas or cclabelbmfont instead.

 

3 cclabelatlas is not only a subclass of cclabelprotocol, but also a subclass of ccatlasnode. ccatlasnode encapsulates a cctextureatlas variable. When the cctextureatlas file is initialized, the image is loaded into the cache (cctexturecache. Cclabelatlas has a high rendering efficiency, but it is too restrictive. It is not as flexible as cclabelbmfont.

 

4 cclabelbmfont is not only a subclass of cclabelprotocol, but also a subclass of ccspritebatchnode. Creating a cclabelbmfont object requires a string and a file in fnt format (font library)

CCLabelBMFont *label= CCLabelBMFont::labelWithString("Bitmap Font Atlas", "fonts/bitmapFontTest.fnt");

 

5.bitmapFontTest.fntThe file contains the following information: The name of the corresponding image (the image contains all the characters you want to draw ),

The Unicode encoding corresponding to the character, the coordinates of the character in the image, and the width. When initializing the cclabelbmfont object, the image is added to the cache (cctexturecache), The fnt file is parsed, and the information in the fnt file is saved to a ccbmfontdef array, the index of the array is charid (the Unicode encoding value of the character ). When you draw a string, find the ccbmfontdef information based on the Unicode code corresponding to the character, retrieve the image from the cache, and then retrieve the character image of the corresponding region based on the coordinates and width and height of ccbmfontdef, add the character index position in the string as a tag to cclabelbmfont, because cclabelbmfont itself is ccspritebatchnode, which implements the batch processing rendering wizard and improves the performance.

 

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.