Now, I have another question.
How to deal with "both" KeyPressed and TextEntered in the while loop? It seems that when there is case sf::Event::TextEntered: , case sf::Event::KeyPressed: will not be detected. Could anyone help me with this, please? Thank you.
while (window.pollEvent(event))
{
switch(event.type)
{
case(sf::Event::Closed):
window.close();
break;
case sf::Event::KeyPressed:
if(event.key.code == sf::Keyboard::Q)
{
sd.play();
}
else if(event.key.code == sf::Keyboard::P)
{
if(music.getStatus() == sf::Sound::Playing)
music.pause();
else
music.play();
}
break;
case sf::Event::TextEntered:
if(event.text.unicode >= 32 && event.text.unicode <= 126)
sentence += static_cast<char>(event.text.unicode);
else if(event.text.unicode == 8 && sentence.getSize() > 0)
sentence.erase(sentence.getSize() - 1, sentence.getSize());
text.setString(sentence);
break;
}
}