473,769 Members | 6,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"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
Jul 19 '05 #1
4 18885
"Shuo Xiang" <sx****@uwaterl oo.ca> 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
Jul 19 '05 #2

"Shuo Xiang" <sx****@uwaterl oo.ca> wrote in message
news:bf******** **@tabloid.uwat erloo.ca...
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
Jul 19 '05 #3

"Shuo Xiang" <sx****@uwaterl oo.ca> wrote in message
news:bf******** **@tabloid.uwat erloo.ca...
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
Jul 19 '05 #4
"Shuo Xiang" <sx****@uwaterl oo.ca> wrote in message
news:bf******** **@tabloid.uwat erloo.ca...
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

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

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
16545
by: Simon Wigzell | last post by:
Can I trap when the scroll is ended? This is what I want - the calculator disapears when the site visitor starts scrolling the main page. I'm doing that with an "onScroll()" function. I'm bringing the calculator back with a "onMouseup()" which I thoguht would activate when the scroll bar was released but it doesn't. What I really want is an "offScroll()" but there is no such thing! ...
5
5215
by: chad.a.morris | last post by:
Hi everyone, I didn't know how to sum this up very well for the title, but hopefully the person(s) will come along who can help. I'm trying to use the window.event.clientX value for positioning a javascript routine, but I'm having trouble. When the javascript routine comes up, it comes up in a certain position based on window.event.clientX. However, the user could click on something in the script display (say, like a menu, or a...
8
14776
by: John | last post by:
Hi all: Is there a C function to make a procedure sleep or delay for a few seconds/minutes on Linux and Sun OS platform? Thanks
3
4412
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here really understand how this could be an issue. The assemblies that the system is complaining about are ones that we build here and we're not changing version numbers on anything. The errors come and go with no apparent rhyme or reason. We do not...
3
4222
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - I have window.status="Moomin"; why doesn't the statusbar change? ----------------------------------------------------------------------- When changing the status in an event (e.g. onmouseover) you should return true from the event. Also a number of browsers require a short delay before setting the status to overcome their default behaviour with the...
7
2396
by: raylaur | last post by:
I'm using a javascript "slide" function to move a <div> layer in 10 pixel increments from one location on a page to another. The layer contains a GIF image. It's basically a side panel that flies out when you click a button. The button is an invisible GIF with an anchor that calls slide() onClick. The animation works fine in IE but in Firefox I'm getting a series of afterimages as the function moves the layer to the goal. The image is painted...
15
2367
by: Steve | last post by:
I am having problems getting values out of an array. The array is set as a global array and values are pushed into it as they are read from a JSON file using a "for loop". When the "for loop" is finished I want to convert the array into a string which can be used by another function. My attempt to do this is not working. The script looks like this: heights=; function getElevationInter(latv,lngv) { var script =...
8
4340
mikek12004
by: mikek12004 | last post by:
1) Script Title: Rich HTML Balloon Tooltip 2) Script URL :http://www.dynamicdrive.com/dynamicindex5/balloontooltip.htm 3) Problem Description: See this page General Music for links you can see without scrolling down the div the tooltip is shown at the desired place but when you scroll donw the div the tooltip's position gets all messed up, e.g in the last "ΤΙΤΛΟΣ ALBUM" (which means Title of album ) the tooltip gets in front of the...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9999
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.