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

Author Topic: Render special characters from a variable  (Read 1723 times)

0 Members and 1 Guest are viewing this topic.

Cadisol87

  • Full Member
  • ***
  • Posts: 129
  • C++ Programmer
    • View Profile
Render special characters from a variable
« on: September 21, 2014, 04:16:32 pm »
I want to render a sf::Text, which contains special characters.
I know that if the text wouldn't be a variable, I could do somenthing like this:
text.setString(L"öüäßê");
But in my case, the text is entered by the user.
How can I render the sf::Text, without having to use a switch statement to check if the character the user entered is a special one?
« Last Edit: September 21, 2014, 04:47:51 pm by Cadisol87 »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Render special characters from a variable
« Reply #1 on: September 21, 2014, 06:08:32 pm »
In what format is the text entered by the user? What data type do you use?

If you use TextEntered event -- as you should if the SFML window is accepting user input -- then you have a sf::Uint32 value representing the character. You can append it to an sf::String object, and then pass that string to sf::Text.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Cadisol87

  • Full Member
  • ***
  • Posts: 129
  • C++ Programmer
    • View Profile
Re: Render special characters from a variable
« Reply #2 on: September 21, 2014, 08:25:44 pm »
Thanks :)
I tried to get the character as a char and then append it to a std::string at first, but now it works perfect.

 

anything