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

Author Topic: sf::Clock doesnt appear to be functioning.  (Read 2856 times)

0 Members and 1 Guest are viewing this topic.

notpedro

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
sf::Clock doesnt appear to be functioning.
« 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)
« Last Edit: February 03, 2015, 12:12:53 pm by notpedro »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Clock doesnt appear to be functioning.
« Reply #1 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.
Laurent Gomila - SFML developer

notpedro

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: sf::Clock doesnt appear to be functioning.
« Reply #2 on: February 03, 2015, 12:20:00 pm »
But eventCount is defined as 0 ? before the while loop.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Clock doesnt appear to be functioning.
« Reply #3 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.
Laurent Gomila - SFML developer