"delay" function

Discussion in 'C++' started by Shuo Xiang, Jul 18, 2003.

  1. Shuo Xiang

    Shuo Xiang Guest

    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
    Shuo Xiang, Jul 18, 2003
    #1
    1. Advertising

  2. "Shuo Xiang" <> wrote...
    > [...] 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).


    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
    Victor Bazarov, Jul 18, 2003
    #2
    1. Advertising

  3. "Shuo Xiang" <> wrote in message
    news:bf9r8v$24q$...
    > 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


    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
    John Harrison, Jul 18, 2003
    #3
  4. "Shuo Xiang" <> wrote in message
    news:bf9r8v$24q$...
    > 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



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


    Regards
    Gavin
    Govindan Chandran, Jul 20, 2003
    #4
  5. "Shuo Xiang" <> wrote in message
    news:bf9r8v$24q$...
    > 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).


    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,
    http://joe.hotchkiss.com

    XXXXXXXXXXXXXXXXXXXXXXXXX
    X joe.hotchkiss X
    X at baesystems.com X
    XXXXXXXXXXXXXXXXXXXXXXXXX
    Joe Hotchkiss, Jul 21, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ingmar Seifert

    Delay of control signals

    Ingmar Seifert, Aug 18, 2003, in forum: VHDL
    Replies:
    0
    Views:
    1,187
    Ingmar Seifert
    Aug 18, 2003
  2. john
    Replies:
    1
    Views:
    571
    Kai Harrekilde-Petersen
    Aug 28, 2003
  3. Kelvin
    Replies:
    0
    Views:
    929
    Kelvin
    Sep 14, 2003
  4. Aryan
    Replies:
    2
    Views:
    406
    S. Justin Gengo
    Sep 11, 2006
  5. Chen Shusheng

    How to write a time delay function?

    Chen Shusheng, Sep 8, 2006, in forum: C Programming
    Replies:
    24
    Views:
    704
    John F
    Sep 11, 2006
Loading...

Share This Page