Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - GentleSlayer

Pages: [1]
1
Window / Re: While pollEvent loop blocks program
« on: November 29, 2017, 12:25:28 am »
Yes, but my actual loop uses the clock named "Timer", which never gets restarted.

2
Window / Re: While pollEvent loop blocks program
« on: November 28, 2017, 11:56:35 pm »
I'm not sure I understand,

I do want the code inside my event loop to only happen when there's an event (which is to skip in this case only if something is pressed).
But I also want the program to flow normally even if there are no events (not sure if I'm clear or not).

3
Window / While pollEvent loop blocks program
« on: November 28, 2017, 11:27:28 pm »
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!

Pages: [1]
anything