You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -51,41 +51,69 @@ We will talk more about the details of the generated texture part in the followi
51
51
##### Label BMFont
52
52
`BMFont` is a label type that uses a bitmap font. Bitmap fonts consist of a matrix of dots or pixels representing the image of each glyph in each face and size. It is very faster and easy to use, but non-scalable, requiring a separate font for each size.
53
53
54
+
As we know from the **Overview** part, the Label class is subclass from SpriteBatchNode. So we could treats each character like a Sprite. This means that each individual character can be:
55
+
56
+
- rotated
57
+
- scaled
58
+
- translated
59
+
- tinted
60
+
- change the opacity
61
+
- It can be used as part of a menu item.
62
+
- anchorPoint can be used to align the "label"
63
+
- Supports AngelCode text format
64
+
65
+
Limitations:
66
+
- All inner characters are using an anchorPoint of (0.5f, 0.5f) and it is not recommend to change it
67
+
because it might affect the rendering
68
+
54
69
In order to create a BMFont label, we should provide two files: A fooBar.fnt file and a fooBar.png file.
55
70
56
71
Here is a figure to show you what these two files look like:
57
72
58
73

59
74
60
-
The underline texture is created through the png file and the information of each individual letter is store in the .fnt file.
75
+
The underline texture is created through the png file and the font information of each individual letter is store in the .fnt file.
61
76
62
77
Here is an sample code to create a BMFont Label:
63
78
64
79
```cpp
65
80
auto myLabel = cocos2d::Label::createWithBMFont("fooBar.fnt", "My Label Text");
66
81
```
67
82
68
-
All of the characters in the second parameter of the above function should be found in the provided booBar.fnt file, otherwise it won't be rendered.
83
+
All of the characters in the second parameter of the above function should be found in the provided "booBar.fnt" file, otherwise it won't be rendered.
69
84
70
-
Let's take the above code snippet as example. If the letter "e" is not in "fooBar.fnt", the final BMFont will be rendered to "My Labl Txt". And there is also a warning log
71
-
in your debug output window.
85
+
Let's take the above code snippet as example. If the letter "e" is not in "fooBar.fnt", the final BMFont will be rendered to "My Labl Txt". And there is also a warning log in your debug output window.
72
86
73
87
When we create a BMFont label, the font face and font size is fixed. We could not change them unless we provide another ".fnt" and ".png" file and create a new BMFont label from them.
74
88
75
89
**Note: There is no `setFontSize` API to change the font size of a BMFont label , nor does it has a unified `setFontSize` API to change the font size of all the other label types.**
76
90
77
91
If you do want achieve different font size with only one BMFont label, you could call Node's `setScale` method. But the outcome might not be accepted. It is recommended to use different BMFont file to achieve the same effect.
78
92
93
+
Use any of these editors to generate BMFonts:
94
+
95
+
-http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
-http://www.angelcode.com/products/bmfont/ (Free, Windows only)
102
+
79
103
80
104
##### Label TTF
81
-
1. TrueType Font
82
-
`TTF` is a label type that uses a True Type Font. You must provide a True Type font file to feed the `Label::createWithTTF` function.
105
+
`TTF` is a label type that uses a True Type Font. You must provide a True Type font file to feed the `Label::createWithTTF` function to create a TTF label.
83
106
84
107
The primary strength of TrueType was originally that it offered font developers a high degree of control over precisely how their fonts are displayed, right down to particular pixels, at various font sizes.
85
108
86
109
When we create a TTF Label , it will create a 512 * 512 texture at first, when we change the Label text, it will search the character from the cached texture. If not found, it will create a new character and put it into the texture. When it reaches the limit of the texture, we will create another 512 * 512 texture and cache the new character in it. Thus we could keep the memory foot print as minimal as possible and also improve text rendering speed.
87
110
88
-
So it will not run as fast as BMFont when changing the Label content during game play frequently.
111
+
Here is a figure to show you the above process:
112
+
113
+

114
+
115
+
116
+
As we can see, TTF label will cache font texture on demand. So it will not run as fast as BMFont when the displayed characters are not cached in the font texture. So if you just want to display a fixed character set like numbers or ASCII letters, and you don't want to change the font property(font face or font size), you'd better use BMFont instead.
89
117
90
118
Here is the code to create a TTF Label with "myfont.ttf":
91
119
@@ -108,7 +136,7 @@ auto mylabel = cocos2d::Label::createWithTTF(labelConfig, "My Label Text");
108
136
109
137
So it mainly be used for displaying Chart message or some static text information.
110
138
111
-
2. SystemFont
139
+
#####SystemFont
112
140
`SystemFont` is a label type that usese the default system font and font size.
0 commit comments