SFML community forums

Help => General => Topic started by: spoty76 on March 25, 2017, 10:30:56 am

Title: Commands issue
Post by: spoty76 on March 25, 2017, 10:30:56 am
Hello, I got a question how to separate commands with the time. For instance:
sound.play();
(then i would like to wait for 3 seconds);
sound2.play();

I tried to use this:
float play = 0;
sound.play();
play += time;
if (play > 3) {sound2.play(); play = 0;}
But this is a cycled thing, and the sound is played each three seconds, I need to do it just once to separate to commands, so how?

Here are some details about what I got:
Windows 10, Visual Studio 2013, sfml 2.4.2
and also these commands:
Clock clock;

   while (window.isOpen())
   {
      float time = clock.getElapsedTime().asMicroseconds();
      clock.restart();

      time = time / 800;
Title: Re: Commands issue
Post by: Hapax on March 25, 2017, 11:43:41 am
One solution would be to keep track of if the second sound has already been played once using a boolean. Just set it to true when you start the second sound but only start the second sound if it is false.
Title: Re: Commands issue
Post by: spoty76 on March 25, 2017, 03:06:13 pm
And what about if I want to wait three seconds before I change view size? For example:
view.setSize(1280, 720);
(wait for three seconds);
view.setSize(640, 400);
I mean not only for view or sound, is it able to wait some time between other commands?
Title: Re: Commands issue
Post by: eXpl0it3r on March 25, 2017, 05:01:03 pm
Then you probably want to setup some scripting system. Where you can define what should happen in which order and with what delay.

This of course is not the only solution, but it's cleaner, than having all kinds of actions hard coded.

As for the general approach, use an sf::Clock to measure the time passed and then do some if-statements to check when it's past the x amount of time.