SFML community forums

Help => System => Topic started by: notpedro on February 03, 2015, 12:09:48 pm

Title: sf::Clock doesnt appear to be functioning.
Post by: notpedro on February 03, 2015, 12:09:48 pm
I am writing some code that will display a makeshift SplashScreen however the sf::Clock module doesnt appear to be working in the way that I had hoped.

I have run the following code:
        sf::Event splashEvent; 
        int eventCount = 0;

        sf::Clock timer;

        while (true)
        {

                if (eventCount == 0)
                {
                        window.clear(sf::Color::White);
                        window.draw(companyLogoSprite);
                        window.display();
                }
                else if (eventCount == 0 && timer.getElapsedTime().asMilliseconds() >= 10)
                {
                        printf("Hello/n");
                        timer.restart();

                        window.clear(sf::Color::White);
                        window.draw(companyLogoSprite);
                        window.display();
                }

                if (eventCount == 1)
                {
                        window.clear(sf::Color::White);
                        window.draw(gameLogoSprite);
                        window.display();
                }
                if (eventCount == 2)
                        return;

                while (window.pollEvent(splashEvent))
                {
                        if (splashEvent.type == sf::Event::EventType::KeyPressed
                                || splashEvent.type == sf::Event::EventType::MouseButtonPressed)
                                eventCount++;
                }
        }

And yet at no point has the console said "Hello". What am I doing wrong? I would be glad of assistance.

(Note that any recommendations on how I have gone about writing this are also very much appreciated)
Title: Re: sf::Clock doesnt appear to be functioning.
Post by: Laurent on February 03, 2015, 12:16:09 pm
Your logic is flawed.

if eventCount is 0, the first block is executed. If it is not 0, the "else if" condition is evaluated, but since eventCount is not 0, it is never true and the corresponding block (that contains your "hello") is never executed.

Nothing to do with sf::Clock.
Title: Re: sf::Clock doesnt appear to be functioning.
Post by: notpedro on February 03, 2015, 12:20:00 pm
But eventCount is defined as 0 ? before the while loop.
Title: Re: sf::Clock doesnt appear to be functioning.
Post by: Laurent on February 03, 2015, 12:33:11 pm
Yes, so it enters the first block ("if") and never the second one ("else if"). Remove the "else" if you want the second block to be executed.