"delay" function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shuo Xiang

    "delay" function

    Greetings:

    I'm working on some graphical game and need to animate certain things (by
    continuously changing the x/y coordinate and update the display), however,
    the system is blinkingly fast so no actual animations can be seen.
    Therefore I need a "delay" function. Is there a "delay" function in C++
    that accepts a time argument in seconds or its varieties (i.e. so that I
    don't have to resort to the "big for loop" scheme).

    Regards,

    Shuo Xiang
  • Victor Bazarov

    #2
    Re: "delay&quo t; function

    "Shuo Xiang" <sxiang@uwaterl oo.ca> wrote...[color=blue]
    > [...] Is there a "delay" function in C++
    > that accepts a time argument in seconds or its varieties (i.e. so that I
    > don't have to resort to the "big for loop" scheme).[/color]

    No. But if you program for one of commonly used platforms,
    it probably has something you could use. Try looking for
    'sleep' or 'Sleep' function. If you can't find any, ask in
    a newsgroup dedicated to your platform.

    Victor


    Comment

    • John Harrison

      #3
      Re: &quot;delay&quo t; function


      "Shuo Xiang" <sxiang@uwaterl oo.ca> wrote in message
      news:bf9r8v$24q $1@tabloid.uwat erloo.ca...[color=blue]
      > Greetings:
      >
      > I'm working on some graphical game and need to animate certain things (by
      > continuously changing the x/y coordinate and update the display), however,
      > the system is blinkingly fast so no actual animations can be seen.
      > Therefore I need a "delay" function. Is there a "delay" function in C++
      > that accepts a time argument in seconds or its varieties (i.e. so that I
      > don't have to resort to the "big for loop" scheme).
      >
      > Regards,
      >
      > Shuo Xiang[/color]

      No there isn't, although its not hard to write your own. But you would do
      much better to use the facilities of whatever operating system you are using
      because it can arrange for other processes to run will you are delaying.

      For instance Windows has a Sleep function, no doubt other O/S have similar.

      john


      Comment

      • Govindan Chandran

        #4
        Re: &quot;delay&quo t; function


        "Shuo Xiang" <sxiang@uwaterl oo.ca> wrote in message
        news:bf9r8v$24q $1@tabloid.uwat erloo.ca...[color=blue]
        > Greetings:
        >
        > I'm working on some graphical game and need to animate certain things (by
        > continuously changing the x/y coordinate and update the display), however,
        > the system is blinkingly fast so no actual animations can be seen.
        > Therefore I need a "delay" function. Is there a "delay" function in C++
        > that accepts a time argument in seconds or its varieties (i.e. so that I
        > don't have to resort to the "big for loop" scheme).
        >
        > Regards,
        >
        > Shuo Xiang[/color]


        Make your program or thread call sleep function, that usually causes some
        delay or lots of delay(usually in milliseconds etc)


        Regards
        Gavin


        Comment

        • Joe Hotchkiss

          #5
          Re: &quot;delay&quo t; function

          "Shuo Xiang" <sxiang@uwaterl oo.ca> wrote in message
          news:bf9r8v$24q $1@tabloid.uwat erloo.ca...[color=blue]
          > I'm working on some graphical game and need to animate certain things (by
          > continuously changing the x/y coordinate and update the display), however,
          > the system is blinkingly fast so no actual animations can be seen.
          > Therefore I need a "delay" function. Is there a "delay" function in C++
          > that accepts a time argument in seconds or its varieties (i.e. so that I
          > don't have to resort to the "big for loop" scheme).[/color]

          I would say that you are taking the wrong approach to this problem.
          Each object should be given a velocity, and then you work out the position
          according to the time at which you draw the frame. In this way, the speed
          at which it moves across the screen is independant of your frame rate or the
          speed of your computer/graphics card.

          ---------------------------------------
          start_time = time
          loop {
          current_time = time
          position = start_position + velocity * (current_time - start_time)
          draw object at calculated position
          }
          ---------------------------------------

          No delays required, and everything moves in a well controlled manner.

          --
          Regards,

          Joe Hotchkiss,


          XXXXXXXXXXXXXXX XXXXXXXXXX
          X joe.hotchkiss X
          X at baesystems.com X
          XXXXXXXXXXXXXXX XXXXXXXXXX



          Comment

          Working...