Applicable version: cocostudio 1.4.0.1
We know that cocostudio with Cocos2d-x development is the most effort-saving choice. However, to achieve this, developers need to have a detailed understanding of almost all the codes in demo-testcpp.
Problem
In the current cocostudio version, an important way to visualize and display numbers is to use the atlaslabel control provided by the UI editor. This control basically corresponds to the cclabelatlas control in demo --- testcpp. Therefore, after understanding the use of the cclabelatlas method, it is very easy to manipulate the atlaslabel control provided by the UI editor of cocostudio through background encoding.
For example, the atlaslabel control settings provided by my UI editor are shown in:
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/46/8F/wKiom1Py-mCimq8_AADIrxk-LXw636.jpg "Title =" Capture. jpg "alt =" wKiom1Py-mCimq8_AADIrxk-LXw636.jpg "/>
The image file corresponding to the preceding control is in PNG format (the characters to be rotated must be of the same width, so that the following parameters can be used for obtaining them ). The content is "0123456789 ". The meanings of several important parameters are as follows:
The first character of the tag: the first character to be obtained from the image file (other characters start with it. Therefore, it is very important to determine the first character, the preceding characters are not displayed)
Label character width: the width of each graphic character
Label character height: the height of each graphic character
Text: the set of all characters to be displayed when you use the control later (probably a subset of the above PNG file character content set)
TIPS:
When setting the preceding parameters, especially when adjusting the "label character width", make sure that all the graphic characters to be displayed in the corresponding control are displayed (preferably exactly ), such as the digital display form on the heart shape. In this way, when the control is assigned a value through the background code of the control, the digital label content can be correctly displayed.
That is to say, the preceding parameter settings are equivalent to initializing the above control using the following background code (from file 'uilabelatlastest. cpp '):
UILabelAtlas* labelAtlas = UILabelAtlas::create(); labelAtlas->setProperty("1234567890", "cocosgui/labelatlas.png", 17, 22, "0"); labelAtlas->setPosition(ccp((widgetSize.width) / 2, widgetSize.height / 2.0f)); m_pUiLayer->addWidget(labelAtlas);
The above code initializes the control. The following code is used to set the actual text data of the control:
//set string value for labelatlas. void setStringValue(const std::string& value);
For the UI control I created using cocostudio above, I used the following code to set the actual numeric string value to be displayed:
LabelAtlas* AtlasLabel_1 = static_cast<LabelAtlas*>(ul->getWidgetByName("AtlasLabel_1"));AtlasLabel_1->setStringValue(CCString::createWithFormat("%d",500)->m_sString);
Summary
It is important to correctly understand the meanings of the above parameters of the atlaslabel control in the UI editor. Otherwise, operations on the background code may be disordered, so that the numeric string to be displayed cannot be properly displayed.
This article from the "Qingfeng" blog, please be sure to keep this source http://zhuxianzhong.blog.51cto.com/157061/1542076