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

Author Topic: Text input  (Read 32682 times)

0 Members and 1 Guest are viewing this topic.

arcticstrat

  • Newbie
  • *
  • Posts: 10
    • View Profile
Text input
« on: March 05, 2010, 03:53:17 pm »
I'm creating a highscores option for my game. When the game finishes, the player can enter their name. How can I get the text they enter in the App window and display it for them to see?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Text input
« Reply #1 on: March 05, 2010, 04:02:33 pm »
sf::Event::TextEntered for input, and sf::String for output.
Laurent Gomila - SFML developer

arcticstrat

  • Newbie
  • *
  • Posts: 10
    • View Profile
Text input
« Reply #2 on: March 05, 2010, 04:08:27 pm »
Could you please show me in code how I'd do this because I'm getting an error that it can't convert sf::Event::EventType to sf::Unicode::Text

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Text input
« Reply #3 on: March 05, 2010, 04:11:25 pm »
Code: [Select]
std::string str;
sf::String text;

// In event loop...
if (event.Type == sf::Event::TextEntered)
{
    // Handle ASCII characters only
    if (event.Text.Unicode < 128)
    {
        str += static_cast<char>(event.Text.Unicode);
        text.SetText(str);
    }
}

// In main loop...
window.Draw(text);
Laurent Gomila - SFML developer

arcticstrat

  • Newbie
  • *
  • Posts: 10
    • View Profile
Text input
« Reply #4 on: March 05, 2010, 04:45:13 pm »
Thanks! Got it working now

michelsteeve

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Text input
« Reply #5 on: March 30, 2010, 08:58:02 am »
Hi I am making similar application in which I have a puzzle game where if you get high score than number of options start decreasing as it's an IQ testing game. But I am not understand how to put stop condition in loop. Because I have tried different conditions but each time either loop break forcefully or went into the infinite loop. Can you guide me what should be the loop condition??

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Text input
« Reply #6 on: March 30, 2010, 01:27:49 pm »
I'm sure that if you could post a source code, all of this will be easier to understand for all of us ;)
Mindiell
----

 

anything