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.fnt
The 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.