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

Author Topic: [SOLVED] can sf::Text have words that each have a different color?  (Read 3074 times)

0 Members and 3 Guests are viewing this topic.

supdawg

  • Newbie
  • *
  • Posts: 33
    • View Profile
the subject says the question. like for example, can i have the words "New Game" but New is red and Game is blue? or do i need to make two different sf::Texts?
« Last Edit: December 08, 2012, 11:02:11 pm by supdawg »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: can sf::Text have words that each have a different color?
« Reply #1 on: December 08, 2012, 01:46:11 am »
It should be easy to do if you copy the code of sf::Text and change some things(just add a method that takes index and color and colors the vertices of the quad at that index, but keep in mind underline is a quad too and it'd not last untill next time quads are recreated so you'd have to do it last:. set font, size, style, text and then set colors), but not with sf::Text , I don't think. And well, the simplest approach is few instances of sf::Text but if you wanted something like 20 letters, that do not change, each in different color, then you should really roll own class up.
« Last Edit: December 08, 2012, 02:08:23 am by FRex »
Back to C++ gamedev with SFML in May 2023

supdawg

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: can sf::Text have words that each have a different color?
« Reply #2 on: December 08, 2012, 05:13:13 am »
oh i see. so wrapping sf::Text is the best option. well i guess itll be a bit of work but i only have a few words that have different colors so far so ill just create multiple sf::Texts each with a different color.

danikaze

  • Newbie
  • *
  • Posts: 38
    • View Profile
    • Email
Re: can sf::Text have words that each have a different color?
« Reply #3 on: December 08, 2012, 07:49:14 am »
what I do is having a wrapper class which accepts format codes (\n, \c[1] for color, \u for underline, etc.) and draws the text into a RenderTarget when update.
Then you only have to draw this RenderTarget into screen ;)

supdawg

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: can sf::Text have words that each have a different color?
« Reply #4 on: December 08, 2012, 11:01:53 pm »
i see. thats an interesting way of doing things. thanks for all the help

 

anything