基本实现原理:
1.设置一个九宫格背景图;如,var imge = new ccui.Scale9Sprite();
2.根据传入的参数 string 和宽度进行设置;
3.默认有一个宽度,读取labelTTF创建的文字高度;
4.设置背景图片的大小;
5.添加文字到该背景图所在的节点层上;
代码例子如下:
auto spriteBg = new cc.Scale9Sprite();
void addString(string str,int width)
{
int spriteW = spriteBg.width;
auto label = new cc.LabelTTF(str,"Arial",20,cc.size(width?width:spriteW,0),对齐方式);
spriteBg.width = label.width;
spriteBg.height = label.height;
this.addChild(label);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。