cocos-js实现文本提示框------根据文字的设置背景框大小

来源:互联网 发布:淘宝潮牌男模特排名 编辑:程序博客网 时间:2024/06/05 07:12

基本实现原理:

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);

}

0 0
原创粉丝点击