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

Author Topic: [2.1] sf::Text wrap at a specific X co-ord  (Read 768 times)

0 Members and 1 Guest are viewing this topic.

makerimages

  • Newbie
  • *
  • Posts: 24
  • Yay!
    • View Profile
    • Email
[2.1] sf::Text wrap at a specific X co-ord
« on: December 11, 2013, 03:03:08 pm »
hey, lets say I have a text like this:
contentT=sf::Text(content,*game->getGuiFont());
        contentT.setColor(sf::Color::Black);
        contentT.setCharacterSize(16);
        contentT.setPosition(xPos-170, yPos-70);
 

and it has a long piece of text(like ddddddddddddddddiwwwwwwwwwwwwwwwwwwwwwwwwwwwaaaaa) in it, the xPos and yPos are relative to the current object these are in, the whole container width is 349px

How could I now make the contentT, when drawed- do a line wrap at lets say xPos+170 ? and go to the next line at xPos-170 again?
Makerimages-It`s in the pixel

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6275
  • Thor Developer
    • View Profile
    • Bromeon
Re: [2.1] sf::Text wrap at a specific X co-ord
« Reply #1 on: December 11, 2013, 03:14:00 pm »
You have to adapt the strings correspondingly. Either you insert "\n" characters or you use multiple sf::Text objects aligned below each other.

To know where to break your string, you have to sum up character widths until your threshold is reached. Have a look at the sf::Font and sf::Glyph classes, they provide you with the information you need.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: [2.1] sf::Text wrap at a specific X co-ord
« Reply #2 on: December 11, 2013, 07:16:52 pm »
Don't forget Text::findCharacterPos.
Laurent Gomila - SFML developer

 

anything