最近在使用3.6版本的richtext遇到getcontentsize的时候会是{0,0};
之后网上查找了一下说使用一下方法:
- var richText = new ccui.RichText();
- richText.ignoreContentAdaptWithSize(false);
- richText.setContentSize(cc.size(500,100));
- richText.pushBackElement(retext); // 10 time
- richText.getVirtualRendererSize();
- richText.ignoreContentAdaptWithSize (true); // the content size will grow with its elements
- richText.formatText (); // force recalculate the content size
- var contentSize = richText.getVirtualRendererSize ();
可以获得大小,但是不能自动换行(手动添加/n是可以的);最后自己是这样解决的:
大小也可以获取,也能自动换行;但是方法比较死;
- var richText = new ccui.RichText();
- richText.pushBackElement(retext); // 10 time
- --添加后在设置
- richText.formatText();
- var size = richText.getContentSize();
- var height = Math.ceil(size.width / 500) * size.height;
- richText.ignoreContentAdaptWithSize(false);
- richText.setContentSize(500,height);
在使用ccui.text创建的文本时,编辑器是自定义大小,也是有效果的。但是生成lua文件以后就没有了自定义大小的效果。要自己重新手动添加
text:ignoreContentAdapWithSize(false)
text:setTextAreaSize(100,50)
使用cocos2.2.8版本的时候,不支持创建一个layout的csd。node的触摸事件是填满整个屏幕,事件会一直派发。所以在裁剪区外的node的按钮事件都可以响应。 解决方案,通过clone,添加到滑动类或者让他继承ccui.Layout
如果直接从lua拿node节点,并设置它的setMetatableindex,他的触摸区域都跑到左下角(未知原因)
导出的lua文件有小数点,会导致偏移。