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

Author Topic: Multiple colours in a single string?  (Read 2497 times)

0 Members and 1 Guest are viewing this topic.

WhiteWind

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Multiple colours in a single string?
« on: February 18, 2013, 05:03:34 pm »
Is something like this possible using text.setString()? Or do I have to make multiple sf::Text variables then just draw them one after the other?..

Haze

  • Full Member
  • ***
  • Posts: 201
    • View Profile
    • Github Profile
Re: Multiple colours in a single string?
« Reply #1 on: February 18, 2013, 05:18:08 pm »
It's not possible using sf::Text, however there is a RichText class available on the wiki, which enables users to set different colors and styles within the same text object.

https://github.com/SFML/SFML/wiki/Source%3A-RichText

WhiteWind

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: Multiple colours in a single string?
« Reply #2 on: February 18, 2013, 05:22:32 pm »
That looks perfect but I'm new to this, how do I 'install' it? Do I just download the .h and .cpp then include in my program?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Multiple colours in a single string?
« Reply #3 on: February 18, 2013, 05:40:22 pm »
Do I just download the .h and .cpp then include in my program?
Yes! :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

WhiteWind

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: Multiple colours in a single string?
« Reply #4 on: February 26, 2013, 04:28:50 am »
So I finally got around to using this. It works well, though you have to set stuff in a certain order (you can't set the font, character size outside of your loop, you should do it directly after setting the string), and I really can't find any way to add new lines.

EDIT: I searched and found an old thread relating to this, but all that was suggested was that they use an STL container to get around the \n issue. Not really sure how I'd go about doing that.
« Last Edit: February 26, 2013, 04:37:39 am by WhiteWind »