SFML community forums

Help => Graphics => Topic started by: Taco_Farmer on May 08, 2014, 07:52:11 pm

Title: New lines in text
Post by: Taco_Farmer on May 08, 2014, 07:52:11 pm
Okay so I am having a pretty difficult time with using multiple rows of text, the only way I could figure out how to do it was making 26 different sf::texts, one for each line. I am going to have to make quite a few paragraphs in this program that I was making so I need to figure out how to do this easier.

I have seen people reference /n (or \n) but I have no clue how to use it and it isn't in the documentation.

This is what the part of my code where I am setting the string looks like:

if(buttongenerate == 0)
                        {
                                cout << "Generating Deb" << endl;
                                button1t.setString("Debra Morgan");
                                button1t.setPosition(264,224);
                                button1t.setCharacterSize(42);
                        }

What would I have to do to make "Debra Morgan" render as

Debra
Morgan

Thanks in Advance
Title: Re: New lines in text
Post by: Laurent on May 08, 2014, 08:09:16 pm
"Debra\nMorgan"

\n is an escape sequence which is interpreted by the compiler as a line break. And sf::Text renders it as expected.
Title: Re: New lines in text
Post by: Taco_Farmer on May 08, 2014, 08:15:17 pm
Thanks, I have no idea how I wasn't able to figure that out. It seems so obvious now.