The script to modify the sprite width and height settings does not work

Please provide the following information when submitting your feedback:

  • Creator version: 2.4.11
  • Target platform: Google Chrome
  • Reproduction method: According to the text width, the script modifies the width of the image grid. I
    modified the rendering attribute online, but it was not found in the API. Then I modified the with, setContentSize, size and other attributes, but it still didn’t work. Finally, I could only write as follows, sizeMode needs to specify 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;

1 Like

After label modifies string, its width and height cannot be obtained immediately. You can use this.node.on to monitor the change of ContentSize

If you want the image to change in size with the text, can’t you just add a layout?