So I've got this little loop in my code:
while(wnd.isOpen()) {
sf::Event myEvent;
while (wnd.pollEvent(myEvent)) {
if (myEvent.type == sf::Event::Closed) {
wnd.close();
}
if (myEvent.type == sf::Event::KeyPressed) {
if (myEvent.key.code == sf::Keyboard::Escape) {
wnd.close();
}
if (myEvent.key.code == sf::Keyboard::Return) {
newLine = true;
}
}
if (myEvent.type == sf::Event::TextEntered) {
if (myEvent.text.unicode == '\b') {
if (!bText.isEmpty()) {
bText.erase(bText.getSize() - 1, 1);
buffer.setString(bText);
}
} else {
bText.insert(bText.getSize(), myEvent.text.unicode);
buffer.setString(bText);
}
}
}
if (newLine == true) {
myTxt.setPosition(0, myTxt.getPosition().y + myTxt.getGlobalBounds().height + 1);
bText.clear();
buffer.setString(bText);
buffer.setPosition(myTxt.getGlobalBounds().width + 1, myTxt.getPosition().y + 1);
newLine = !newLine;
}
wnd.draw(myTxt);
wnd.draw(buffer);
/*
if (myClock.getElapsedTime() >= sf::milliseconds(500)) {
myClock.restart();
showCursor = !showCursor;
}
if(showCursor == true) {
cursor = "_";
myCursor.setPosition(myTxt.getGlobalBounds().width + buffer.getGlobalBounds().width + 1, myTxt.getPosition().y + 1);
} else {
cursor.clear();
}
wnd.draw(myCursor);
*/
wnd.display();
}
It works like a charm. However the application doesn't erase the last character printed on the screen when [BACKSPACE] is pressed. Can anyone explain why this is happening and how to fix this?