This title is called setdimensions. The reason why I want to get a dialog box function for automatic line feed is that I think of how to automatically line feed.
You can see a function called setdimensions and set the area that can be displayed. If you have found some examples on the internet, it seems that the line feed is really amazing.
However, the new helloworld example found a problem. The Code is as follows:
Cclabelttf * plabel = cclabelttf: Create ("Hello World", "Arial", 24 );
Plabel-> setdimensions (ccsizemake (50, 0); // set the display area
Plabel-> sethorizontalalignment (kcctextalignmentleft); // align horizontally to the left
// Position the label on the center of the screen
Plabel-> setposition (CCP (origin. x + visiblesize. width/2,
Origin. Y + visiblesize. Height-plabel-> getcontentsize (). Height ));
// Add the label as a child to this layer
This-> addchild (plabel, 1 );
The result is as follows:
We can see that there is less ~ If you set the width (ccsizemake (50, 0), the smaller the width, the more powerful it is.
Okay, continue the experiment. If you change "Hello World" to "helloworld", the effect will be different. Remove the spaces in the middle.
This is the result.
There is no line break. Here we can think of spaces as the \ n line break. In this case, English words are not separated.
Let's take a look at the Chinese display.
There is no problem in Chinese display. This is because Chinese is a single word and cannot be connected as English. Therefore, the multi-line display for Chinese is OK.
Therefore, you can use this method to lazy the display of Chinese characters.
What should I do if multiple lines are displayed in English? What should I do if the multi-line display is mixed between Chinese and English?
Let us give you a thought: in general terms, we can only calculate the length based on the encoding. If the length is enough, we can add a line break to the end or re-create a new cclabelttf.
You can combine these to implement line breaks.
Reprinted from http://blog.csdn.net/nynyvkhhiiii/article/details/16987899
Multi-line display of cclabelttf (Chinese only)