hello everybody
i made a simple intro screen, where it fades in a image, waits for the user to press anything in the keyboard, and then fades out the image.
the problem is that if the user press any button before the image is completely showing in the screen, it fades in and out directly (instead of fading in and only then accepting user inputs)
this is the code (game_sys_p is an object that holds the sf::Window; and intro1_spr is a sf::Sprite)
sf::Event intro_events;
int fade_factor = 1;
for (int i=0; i>=0; i+=5*fade_factor){
game_sys_p.getGameWindow().clear(sf::Color(0, 0, 0, i));
intro1_spr.setColor(sf::Color(255, 255, 255, i));
game_sys_p.getGameWindow().draw(intro1_spr);
game_sys_p.getGameWindow().display();
if (i>=255){
fade_factor=-1;
while (intro_events.type != sf::Event::KeyPressed){
game_sys_p.getGameWindow().pollEvent(intro_events);
sf::sleep(sf::milliseconds(10));
}
}
sf::sleep(sf::milliseconds(20));
}
i believe this happens because sf::Event is queueing the events (and i think it is expected). is there any way to prevent that?
or any change i could do to the code to fix it? any suggestion is welcome
thanks in advance!