Hello There!Lately, I have been trying to get used to the "sf::Clock" class in SFML. Specifically, I have been trying to make a typing text effect. Here is the function responsible for drawing the text with said effect:
void Dialogue::Type(sf::RenderWindow &window)
{
delta_time = curr_time - rec_time;
if(delta_time == 50 && chr < str.size())
{
chr++;
text.setString(sf::String(str.substr(0, chr)));
rec_time = clock.getElapsedTime().asMilliseconds();
curr_time = rec_time;
}
else
curr_time = clock.getElapsedTime().asMilliseconds();
window.draw(text);
}
and inside my main function and while(window.isOpen()) loop, I call the function:
window.clear();
//-------------//
dial.Type(window);
//--------------//
window.display();
Even if I haven't noticed any error with the way I wrote my code, the application will freeze randomly when typing a phrase. The phrase was "This is a typing-effect test" and the application would be stuck in random times (for example it would write "This is a typ" and then it wouldn't continue). The window would respond but the code would not execute any further as it should. The same behaviour was shown other times I tried using sf::Clock, like when I tried making a timer (the timer would stop counting the time at random). What is causing that and how can I repair it? (I am using Visual Studio 2017)