Problems formatting RichText in cocos2d-html5

Problems formatting RichText in cocos2d-html5
0.0 0


I am trying to display a line of text that contains a section that is a different color from the rest of the text and that will be changed during the game. eg, ‘I had a ______ day today.’, where the blank would be colored blue and would be replaced via user interaction to something like ‘I had a bad day today.’, with ‘bad’ colored blue. You get the idea.

From what I have read, RichText should do this by pushing the different RichElementTexts to the RichText node. And it does display text. However, the position of the text is varying based on (it appears) the length of the text, and it’s not wrapping, even when I specify a content size.

This is how I’m adding the RichText to a layer:

const label = new ccui.RichText();
label.setPosition(100, 120);
this.setAnchorPoint(0, 1);
this.ignoreContentAdaptWithSize(true); // I've tried this on and off, with no difference in display

const text = 'A long string of text that I can\'t get to position or wrap correctly - it causes quite a bit of frustration.';
const stemElement = new ccui.RichElementText(0, cc.color('#000000'), 255, text, 'Arial', 20);
label.setContentSize(cc.size(50, 100)); // I've also tried label.setContentSize(50, 100);

Unfortunately, the problem persists. What am I doing wrong?