Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Displaying multiple lines of text using sf::String  (Read 6446 times)

0 Members and 1 Guest are viewing this topic.

rojan_neo

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • http://makeagame.tumblr.com
Displaying multiple lines of text using sf::String
« on: December 20, 2011, 01:22:33 pm »
How would I display multiple lines of text using one sf::String variable in SFML 1.6?? For example if I use SetText Function for a very long text then it just goes out of bound and the text that falls beyond the size of the window is not displayed!!
How would make something like whenever the text goes out of bound it automatically shifts the text to the next line??

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Displaying multiple lines of text using sf::String
« Reply #1 on: December 20, 2011, 01:31:36 pm »
You can insert a '\n' character after each character of the string that is located beyond the container's width.
Laurent Gomila - SFML developer

rojan_neo

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • http://makeagame.tumblr.com
Displaying multiple lines of text using sf::String
« Reply #2 on: December 21, 2011, 11:52:39 am »
Quote from: "Laurent"
You can insert a '\n' character after each character of the string that is located beyond the container's width.

Do you mean like:
Code: [Select]

sf::String testString;
testString.SetText("one line \n next line");

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Displaying multiple lines of text using sf::String
« Reply #3 on: December 21, 2011, 11:57:14 am »
Yes.
Laurent Gomila - SFML developer

rojan_neo

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • http://makeagame.tumblr.com
Displaying multiple lines of text using sf::String
« Reply #4 on: December 21, 2011, 12:08:57 pm »
This works fine when I do this directly within the code.. but since the text that i want tor set is in a text file I read the contents of the file and store the text in std::string variable and do :
Code: [Select]


testString.SetText(stringvariable);

Now when I supply \n character as the content of the file it does not change the line of the sf::String as it used to in previous example!
Any Idea how I'll get through this??

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Displaying multiple lines of text using sf::String
« Reply #5 on: December 21, 2011, 01:17:42 pm »
You don't have to write "\n" in your text file, '\n' is the character that represents a new line in a C++ literal string. Just having lines in your text file is enough to have lines in your sf::String :)

Maybe the end of lines are dropped when you read the contents of the file. Can you show how you read it?
Laurent Gomila - SFML developer

 

anything