cocos2dx CCLabelTTF 字体自动换行
来源:互联网 发布:windows网络编程pdf 编辑:程序博客网 时间:2024/05/17 04:30
我用的2.1.4版本的引擎,搞的我头疼死了。我也是在网上抄的一份,各种不行,然后自己修改他的,就可以了。
void initString() { //将中文进行转换为TTFstd::string_string = tipsInfo.tipsString; //初始化Tips字符串int index = 0;int index_max = strlen(_string.c_str());bool is_end = false;if (labelTTF_arr != nullptr){labelTTF_arr->removeAllObjects();} else{labelTTF_arr = CCArray::create();labelTTF_arr->retain();}while (! is_end) { //格式转化//以上步骤是根据ASCII码找出中英文字符,并创建成一个CCLabelTTF对象存入labelTTF_arr数组中。if (_string[index] >= 0 && _string[index] <= 127) {string englishStr =_string.substr(index, 1).c_str();labelTTF_arr->addObject(CCLabelTTF::create(englishStr.c_str(), fontMakertFilePath, 12));index += 1;}else{string chineseStr = _string.substr(index, 3).c_str();labelTTF_arr->addObject(CCLabelTTF::create(chineseStr.c_str(), fontMakertFilePath, 12));index += 3;}if (index >= index_max) {is_end = true;}}initStringFormat(8, 10, 250); //设置对齐方式}void initStringFormat(float horizontalSpacing, float verticalSpacing, float lineWidth) {//下面创建的原理是在CCLabelTTF对象上添加子对象CCLabelTTF,以此组合成一句话,以左上角第一个字为锚点。。CCLabelTTF* pWillShowWords= (CCLabelTTF*)labelTTF_arr->objectAtIndex(0);float nowWidth= pWillShowWords->getContentSize().width;CCLabelTTF* pCurrentTTF= pWillShowWords;CCLabelTTF* pBeginTTF= pWillShowWords;int arr_count = labelTTF_arr->count();for (int i=1; i < arr_count; i++) {CCLabelTTF* updateTTF = (CCLabelTTF*)labelTTF_arr->objectAtIndex(i);updateTTF->setAnchorPoint(ccp(0.0f, 0.5f));const char *pLineBreak = ((CCLabelTTF *)labelTTF_arr->objectAtIndex(i))->getString();nowWidth += updateTTF->getContentSize().width;if (nowWidth >= lineWidth || (std::strcmp(pLineBreak, "\n") == 0)) {nowWidth = pWillShowWords->getContentSize().width;if (std::strcmp(pLineBreak, "\n") == 0)//在你的字符串里面添加一个\n字符,其他字符也行(表示换行){nowWidth = lineWidth; //换行continue;} updateTTF->setPosition(ccp(0, -pCurrentTTF->getContentSize().height * 0.5 - verticalSpacing));pCurrentTTF = pBeginTTF;pBeginTTF = updateTTF;}else{updateTTF->setPosition(ccp(pCurrentTTF->getContentSize().width + horizontalSpacing, pCurrentTTF->getContentSize().height * 0.5));}pCurrentTTF->addChild(updateTTF);pCurrentTTF = updateTTF;}this->addChild(pWillShowWords, 100); //test//TODO///设置你字体坐标:pWillShowWords->setPosition(..)}
0 0
- cocos2dx CCLabelTTF 字体自动换行
- cocos2dx windows phone平台下CCLabelTTF自动换行的实现
- cocos2dx windows phone平台下CCLabelTTF自动换行的实现(2)
- cocos2dx CCLabelTTF自定义字体的使用
- Cocos2dx CCLabelAtlas字体与CCLabelTTF字体的使用方法
- c1FlexGrid1\字体自动换行
- 对CCLabelTTF进行自动换行,显示打字效果(转)
- CCLabelTTF之换行
- CCLabelTTF 换行操作
- Cocos2dx-CCLabelTTF变黑
- cocos2dx的CCLabelTTF类使用不同的TTF字库时字体没有变化的问题
- cocos2dX UI控件之CCLabelTTF
- cocos2dX UI控件之CCLabelTTF
- cocos2dx CCLabelTTF显示中文乱码
- DIV层中字体自动换行
- ios UILabel 自动换行,缩小字体代码
- phpstrom 字体 注释修改 自动换行
- cocos2dx之文本渲染(CCLabelAtlas,CCLableBMFont,CCLabelTTF)
- mysql怎样创建名称有特殊字符的数据库
- 网页字体参考
- 常用cmd命令
- bcrypt使用
- elasticsearch java API------与集群交互
- cocos2dx CCLabelTTF 字体自动换行
- unity--sendMeassage
- C++ goto 在g++ 编译时出现 crosses initialization 和 jump to label xxx [-fpermissive] 错误
- k阶原点距和k阶中心距各是说明什么数字特征
- 解决从github下载web的源码部署到eclipse的问题
- Android调用so文件(C代码库)方法详解
- gdb命令小结
- My97DatePicker控件显示时分秒
- github创建工程