I have a fade animation and some shape movement on the screen. the enter key causes the screen to fade out and in. i noticed that if i press the enter key while moving my mouse in the window, the fade animation happens faster.
here is my main loop:
while(Window.isOpen()){
while(Window.pollEvent(ScreenManager::getInstance().event)){
if(ScreenManager::getInstance().event.type == sf::Event::Closed)
Window.close();
if(ScreenManager::getInstance().event.key.code == sf::Keyboard::Escape)
Window.close();
else
ScreenManager::getInstance().update(ScreenManager::getInstance().event, Window);
}//end of while Poll event
Window.clear(sf::Color(0, 0, 0));
ScreenManager::getInstance().update(ScreenManager::getInstance().event, Window);
ScreenManager::getInstance().draw(Window);
Window.display();
ScreenManager::getInstance().timeBetwFrame = clock.restart(); //records time between frame
}//end of while isOpen
as you probably saw, i call my update function twice, once in the event loop and again in the while(Window is open) loop. the reason for this is this: if the user presses enter and then does nothing after that, i want the window to do the fade animation. however if i have update only in the event loop, then it wont call update since after pressing enter, there are no more events to pop so it wont even be in the event loop. and if update is only outside the event loop, then if an event happens, i wont call update until all events are popped and im outside the event loop. so i have a call to update twice. now you may say that in my event loop, i should say
if(sf::Event::isKeyPressed) //call update function
however this still isnt that great of a solution.
my update function does everything for me: input handling, window switching, animation, etc etc. but after one event (say pressing enter) to actually completely do the whole animation, update has to be called a few times since every frame, i change the alpha value by a bit (for fade animation). so i think the two calls to the update function makes the fade animation speed up if i move my mouse when pressing enter since many events are happening so its calling udpate once in the event loop and once in the while(isOpen) loop.
i cant think of any solution to this problem that works with the way i have set up my program. can anyone help me out with this issue please? thanks