Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > "delay" function

Reply
Thread Tools

"delay" function

 
 
Shuo Xiang
Guest
Posts: n/a
 
      07-18-2003
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
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      07-18-2003
"Shuo Xiang" <(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      07-18-2003

"Shuo Xiang" <(E-Mail Removed)> wrote in message
news:bf9r8v$24q$(E-Mail Removed)...
> 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


 
Reply With Quote
 
Govindan Chandran
Guest
Posts: n/a
 
      07-20-2003

"Shuo Xiang" <(E-Mail Removed)> wrote in message
news:bf9r8v$24q$(E-Mail Removed)...
> 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


 
Reply With Quote
 
Joe Hotchkiss
Guest
Posts: n/a
 
      07-21-2003
"Shuo Xiang" <(E-Mail Removed)> wrote in message
news:bf9r8v$24q$(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function versus pointer to function, in context of std::function,huh? Alf P. Steinbach C++ 10 07-27-2011 05:51 AM
Function pointer to void function and int function Giannis Papadopoulos C Programming 5 09-05-2005 09:06 PM
How override ALL function calls? (Is there a "function call function"?) seberino@spawar.navy.mil Python 2 08-01-2005 12:38 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
Passing a C++ object's member function to a C function expecing a function pointer! James Vanns C++ 7 01-21-2004 02:39 AM



Advertisments