脚本修改精灵宽高 设置不起作用

反馈时请提供以下信息:

  • Creator 版本:2.4.11

  • 目标平台:谷歌游览器

  • 重现方式:根据文本宽度,脚本修改图片九宫格宽度
    网上修改渲染的那个属性,api中没找到,然后修改了with,setContentSize,size等属性,任然不起作用,最后只能如下写,sizeMode需要指定CUSTOM

this.character_left_long = this.character_left.getChildByName(‘dialogue’);
this.character_left_long_label = this.character_left_long.getChildByName(‘words’).getComponent(cc.Label);
this.character_left_long_label.string = source_json[num_len]
this.character_left_long.width = this.character_left_long_label.node.width + 30;
this.character_left_long.active = true;
this.character_left_long.width = this.character_left_long_label.node.width + 30;
this.character_left_long.active = false;
this.character_left_long.width = this.character_left_long_label.node.width + 30;
this.character_left_long.active = true;

label 修改 string 后无法立刻取到其宽高。可以使用 this.node.on 监听 ContentSize 的改变

如果说你是像让图片跟随文本的大小变化,挂个layout不就可以了吗

谢谢,感谢

跟兄弟跨年对话 :cow: :beer:

this.constent.string = data.content;
this.constent._forceUpdateRenderData();
this.ContentBg.node.width = this.constent.node.width + 35;
this.ContentBg.node.height = this.constent.node.height + 15;
if (this.constent.node.width >= 420) {
this.constent.overflow = cc.Label.Overflow.RESIZE_HEIGHT;
this.constent.node.width = 420;
this.ContentBg.node.width = this.constent.node.width + 35;
this.ContentBg.node.height = this.constent.node.height + 35;
}