cocos2dx《单机斗地主》源码解剖之六 玩家(人)的出牌(1) ----------------- http://blog.csdn.net/oiy37215/article/details/43795819
--------------//卡的走不动, 如何提高体验/帧率:
通过上下对比. for时多加一些判断, 符合条件在执行
void UIChat::autoWrapStringByWidth(std::string &str, float fWidth)
{
Label *_label = Label::createWithSystemFont("", "", 36);
for (int i = 0; i<str.length(); ++i)
{
std::string _strTemp(str.begin(), str.begin() + i);
_label->setString(A2U8(_strTemp));
if (_label->getContentSize().width > fWidth)
{
str.insert(str.begin()+(i), '\n');
// return;
}
}
/*
string subStr;
Label* label = Label::createWithSystemFont("", "", 36);
int subN = 0;
int nCount = 0;
for (int i = 0; i < str.length(); i++)
{
if ((subN + nCount) < str.length())
{
subStr = str.substr(subN, nCount);
label->setString(A2U8(subStr));
if (label->getContentSize().width >= fWidth)
{
str.insert(i - 1, "\n");
subN = i;
nCount = 0;
}
nCount++;
}
}
*/
return;
}
//****************************************************改进
Label *_label = Label::createWithSystemFont("", "", 36);
std::string _content = str;
WjsUtf82AsciiEx(_content); //编码方式转2次就没了
for (int i = 0; i < str.length(); ++i)
{
if (i > 40 && i <48) //22个汉字 -----------------就加一个判断就不卡了 --- 加在最外层
{
std::string _strTemp(str.begin(), str.begin() + i);
_label->setString(A2U8(_strTemp));
if (_label->getContentSize().width > fWidth)
{
str.insert(str.begin() + (i), '\n');
break; -------------------------------------优化 减少循环
}
}
}