The following code produces some odd behavior. As the attached pictures show, I am able to input text just fine, but when I press backspace, it changes the last character to that little circle, after which pressing backspace again does nothing. This seems to imply to me that the place in the sf::string which once held the last character still exists, and that pressing backspace repeatedly just continually replaces the last character with the little circle. Hence, the string has not changes size, and calling getSize() will continue to produce the same number at every frame. Is this supposed to be the case, or am I doing something wrong? Thank you for your help.
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::Font myFont;
if (!myFont.loadFromFile("resources/roman.ttf"))
{
cout << "The font was not loaded!\n";
}
sf::Text Text;
Text.setFont(myFont);
Text.setCharacterSize(24);
Text.setColor(sf::Color::Red);
Text.setPosition(10, 10);
sf::String userInput;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
window.close();
}
if (event.type == sf::Event::TextEntered)
{
userInput.insert(userInput.getSize(), event.text.unicode);
}
if (event.type == sf::Event::KeyPressed)
{
if (event.key.code == sf::Keyboard::BackSpace)
{
userInput.erase(userInput.getSize() - 1,1);
}
}
}
Text.setString(userInput.getData());
window.clear();
window.draw(Text);
window.display();
}
return 0;
}