cocos2d使用问题

前端之家收集整理的这篇文章主要介绍了cocos2d使用问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

最近在使用3.6版本的richtext遇到getcontentsize的时候会是{0,0};

  1. var richText = new ccui.RichText();
  2. richText.ignoreContentAdaptWithSize(false);
  3. richText.setContentSize(cc.size(500,100));
  4. richText.pushBackElement(retext); // 10 time
  5. richText.getVirtualRendererSize();
之后网上查找了一下说使用一下方法

  1. richText.ignoreContentAdaptWithSize (true); // the content size will grow with its elements
  2. richText.formatText (); // force recalculate the content size
  3. var contentSize = richText.getVirtualRendererSize ();

可以获得大小,但是不能自动换行(手动添加/n是可以的);最后自己是这样解决的:

  1. var richText = new ccui.RichText();
  2. richText.pushBackElement(retext); // 10 time
  3. --添加后在设置
  4. richText.formatText();
  5. var size = richText.getContentSize();
  6. var height = Math.ceil(size.width / 500) * size.height;
  7. richText.ignoreContentAdaptWithSize(false);
  8. 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文件有小数点,会导致偏移。

猜你在找的Cocos2d-x相关文章