Hello!
I started using SFML a week or so ago and I have a little problem that has been bugging me for a while now(but not major enough to stop me from working on my project).
I added a "Logo Screen" where I simply fade in and out an animated picture and switch to the next screen after a few seconds or if a button/mouse click happens.
void logoScreen::show(sf::RenderWindow& app) {
sf::Texture texture;
texture.loadFromFile("Images/Logo.png");
sf::IntRect rectSourceSprite(0, 0, 784, 472);
sf::Sprite sprite(texture,rectSourceSprite);
sprite.setOrigin(sprite.getGlobalBounds().width / 2, sprite.getGlobalBounds().height / 2);
sprite.setPosition(app.getSize().x / 2, app.getSize().y / 2);
sf::Clock timer;
sf::Clock animate;
sf::Event event;
while (timer.getElapsedTime().asSeconds() < 5.0f) {
// Doing anything will skip the logo
while (app.pollEvent(event)) {
if (event.type == sf::Event::EventType::MouseButtonPressed || event.type == sf::Event::EventType::KeyPressed) {
return;
}
}
if (animate.getElapsedTime().asSeconds() > 0.1f) {
if (rectSourceSprite.left == 784 * 4) {
rectSourceSprite.left = 0;
if (rectSourceSprite.top < 472 * 5) {
rectSourceSprite.top += 472;
}
}
// This is when the logo pauses before fading off
else if (rectSourceSprite.left == 784 * 2 && rectSourceSprite.top == 472 * 4) {
// Resume animation when timer reaches 4.8s
if (timer.getElapsedTime().asSeconds() > 4.8f) {
rectSourceSprite.left += 784;
rectSourceSprite.top += 472;
}
}
else {
rectSourceSprite.left += 784;
}
sprite.setTextureRect(rectSourceSprite);
animate.restart();
}
app.clear(sf::Color(255,255,255,255));
app.draw(sprite);
app.display();
}
return;
}
The problem is that if I dont move the mouse (or anything) when the timer reaches 5 seconds, the program just waits there for something to happen. Strangely enough, when I'm debbugging the application this problem doesn't occur. I know the problem is the pollEvent call because when I remove it the application works fine (but then I can't skip the logo). I don't understand why it's blocking the loop.
Thank you for you help!