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

Author Topic: Commands issue  (Read 877 times)

0 Members and 1 Guest are viewing this topic.

spoty76

  • Newbie
  • *
  • Posts: 21
    • View Profile
Commands issue
« 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;
« Last Edit: March 25, 2017, 10:56:38 am by spoty76 »

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Commands issue
« Reply #1 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

spoty76

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Commands issue
« Reply #2 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: Commands issue
« Reply #3 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything