Positioning Labels

Hello! First of all sorry about my english, its not perfect, but I hope you understande me :smiley:. I’m making a videogame where the main thing is reading and I’m having trouble with the labels I try to instantiate, this is the code I use to instantiate a prefab which is mainly a Label:

let text = cc.instantiate(this.words);
            text.parent = content;
            text.getComponent(cc.Label).fontSize = 40;
            text.getComponent(cc.Label).string = wordArray[i];
            text.getComponent(cc.Label).string = text.getComponent(cc.Label).string.replace(/<.*?>/g, "");
            text.setPosition(0, -50-gGlobalConstants.HEIGHT_WORD_SLIDER * i);

Well this works pretty well except for one thing, the problem is about how it is seen in the screen, all of them are childs of the same node and their positionX is set to 0, but when I simulate it, this is how it is shown:

The nodes doesn’t seem to be in the same positionX, even the ones with the same number of letters.

Since the presentation of the game is pretty important, is there any way to fix it?

Many thanks :smiley:

Add a widget to it and stretch the label to 0px left and 0px right. Then make sure the label is set to center.

1 Like