RichText Problem

Hello,

Do you know how can i add a return to line with a RichText ? I try “\n” but it dont work good. Or do you know if it exist a HtmlLabel with cocos2d-x for mix bold text and italic text in the same label ?

This is the result i have :

And my code :

RichText * r = RichText::create();
r->setPosition(Vec2(300, 400));
r->setContentSize(Size(400, 400));
this->addChild®;

RichElementText* re1 = RichElementText::create(1, Color3B::BLACK, 255, "Bonjour\n", "fonts/FuturaHandw1ritten.ttf", 30);
r->pushBackElement(re1);
RichElementText* re2 = RichElementText::create(1, Color3B::BLACK, 255, "au revoir", "fonts/FuturaHandw1ritten.ttf", 30);
r->pushBackElement(re2);

In advance thanks,

Interesting. Probably just a missing feature. What happens if you put it in the middle of the word? “Bon\njour”

Also your image is not what it would look like if the new line character was working correctly. It would instead put “au revoir” directly under “Bonjour” like:

Bonjour\n
au revoir

You can try “Bonjour\r\n” it could work if you are on Windows and if RichText feature is plateform dependent.
Edit: It’s not workin, the “\n” is not properly implemented in RichText, this jump to new line on the Element itself.

1 Like

Thanks for yours answers,
Unfortunaly, “Bonjour\r\n” do the same things that “Bonjour\n”.
And if i try “bonjour\nau revoir”, that works but its not what i want because i want mix normal and bold text, its why i use the RichText. For example, i want normal text on the first line and bold text on the second line.

Yep, understood, but did you try “bonjour\nau revoir” as the string for a single RichTextElement? I’m just curious to narrow down what the bug is, whether it’s new line parsing issue or a new line at the end of an element issue.

Yes i try “bonjour\nau revoir” in a single RichTextElement and it work. The issue its when you want to use “\n” in a second RichTextElement, the new line start at the end of the first element : the first element->getContentSize().width().

I see something interesting, the RichText class have a “addNewLine ()” function in its Protected Member Functions.

http://www.cocos2d-x.org/reference/native-cpp/V2.2.3/dd/d4b/classcocos2d_1_1ui_1_1_rich_text.html

1 Like