Cocostudio Study Notes (5) Text + TextAtlas + TextBMFont, cocostudio
In the afternoon, a group of college students visited our company and learned how to develop a game...
The controls studied tonight are three labels: Text, TextAtlas, and TextBMFont.
In cocostudio, I first drag all three labels into the scene and name them label, atlas, and bitMap respectively. Finally, export the project and load the Widget in cocos2dx.
cocos2d::ui::Widget* labelUI = GUIReader::getInstance()->widgetFromJsonFile("LabelUI/LabelUI_1.json");this->addChild(labelUI,2);
Some people may say that since cocos2d: ui scope has been declared before, why not directly use widgets here? My answer is that I am also a newbie and I am not used to writing these APIs, so I can only use this method to deepen my impression.
I. Read Text first
1. Extract the label from the Widget.The Code is as follows:
Text* m_label = static_cast<Text*>(Helper::seekWidgetByName(labelUI,"label"));m_label->setPosition(Point(300,300));
2. Check the source code of Text.:
Static Text * create (); // create static Text * create (const std: string & textContent, const std: string & fontName, int fontSize ); void setText (const std: string & text); // set the displayed text const std: string & getStringValue (); obtain the text content ssize_t getStringLength (); // obtain the string length in text
Actually, it is similar to how to use the Label in cocos2dx.
Ii. TextAtlas
1. Retrieve the widgets in the label
TextAtlas* m_atlas = static_cast<TextAtlas*>(Helper::seekWidgetByName(labelUI,"atals"));m_atlas->setPosition(Point(400,300));
2. speechless
3. TextBMFont
1. Extract the label from the Widget.
TextBMFont* m_bmf = static_cast<TextBMFont*>(Helper::seekWidgetByName(labelUI,"bitMap"));m_bmf->setPosition(Point(200,300));
2. speechless
4. Conclusion: I did not give a more in-depth introduction to the above because I found that the Text in cocostudio is almost the same as the Label in cocos2dx, so I am too lazy to introduce it. Previously, the blog gave a clear introduction to the Label after 3.0.
Respect Original, reprinted please indicate Source: http://blog.csdn.net/star530/article/details/37370285