SFML community forums

Help => Window => Topic started by: arcticstrat on March 05, 2010, 03:53:17 pm

Title: Text input
Post by: arcticstrat 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?
Title: Text input
Post by: Laurent on March 05, 2010, 04:02:33 pm
sf::Event::TextEntered for input, and sf::String for output.
Title: Text input
Post by: arcticstrat 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
Title: Text input
Post by: Laurent 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);
Title: Text input
Post by: arcticstrat on March 05, 2010, 04:45:13 pm
Thanks! Got it working now
Title: Text input
Post by: michelsteeve 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??
Title: Text input
Post by: Mindiell 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 ;)