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

基本实现原理:

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

}

猜你喜欢

转载自blog.csdn.net/tang_bo_hu_2011/article/details/49915575