Cocos2dx lua Label的换行
2015-01-07 11:00
591 查看
参考了star特530的博客。原文链接
按照上文去做,如果遇到文本是中英混合就会出现中文乱码。以下是改进后的方法
按照上文去做,如果遇到文本是中英混合就会出现中文乱码。以下是改进后的方法
-- Label文本换行 function FunSetLinefeed( strText, nLineWidth ) --文本,行宽 --读取每个字符做中文英文判断,并且记录大小 local nStep = 1 local index = 1 local ltabTextSize = {} while true do c = string.sub(strText, nStep, nStep) b = string.byte(c) if b > 128 then ltabTextSize[index] = 3 nStep = nStep + 3 index = index + 1 else ltabTextSize[index] = 1 nStep = nStep + 1 index = index + 1 end if nStep > #strText then break end end --将字符按照限定行宽进行分组 local nLineCount = 1 local nBeginPos = 1 local lptrCurText = nil local ltabText = {} local nCurSize = 0 for i = 1, index - 1 do nCurSize = nCurSize + ltabTextSize[i] if nCurSize > nLineWidth then nCurSize = nCurSize - ltabTextSize[i] ltabText[nLineCount] = string.sub( strText, nBeginPos, nBeginPos + nCurSize - 1 ) nBeginPos = nBeginPos + nCurSize nCurSize = ltabTextSize[i] nLineCount = nLineCount + 1 end end for i = 1, nLineCount - 1 do if lptrCurText == nil then lptrCurText = ltabText[i] else lptrCurText = lptrCurText .. "\n" .. ltabText[i] end end return lptrCurText end
相关文章推荐
- Cocos2dx 小技巧 Label的换行(js实现)
- cocostudio 实现换行功能的label (文本区) lua
- Cocos2dx 小技巧(三)Label的换行
- 修复cocos2dx的Label,WP8下不能换行的问题
- Cocos2dx 小技巧 Label的换行(js实现)
- cocos2dx之Label实现换行
- cocos2dx3.2 Label 自动换行,各种label创建方式,描边,阴影,发光等;
- cocos2dx windows phone平台下CCLabelTTF自己主动换行的实现(2)
- C# WinForm中的Label换行方法
- cocos2dx--vs2012+lua开发环境搭建
- cocos2dx 在 Mac 下创建 lua 工程总结
- [小技巧]asp.net Label 自动换行
- [cocos2dx_Lua]quick中的节点事件
- Cocos2dx lua 横向滚动字幕实现
- C# Label显示多行文本及换行(WinForm/WebForm)
- cocos2dx原生lua绑定工具的总结
- cocos2dx添加文本的三种方法及适用情况CCLabelTTF,CCLabelBMFont,CCLabelAtlas
- cocos2dx使用lua和protobuf
- cocos2dx3.1-lua移植到android流程
- cocos2dx一行添加Sprite,Label