473,773 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

setTimeOut vs time-based animation

hi...

I've recently created a dhtml thing on http://www.shapers.nl/ that
animates a lot of images. The thing I want to solve is the lag that
occurs when a new animation is initiated.

To make it time-based I calculate the entire animation on beforehand
and create numerous setTimeOuts in a repeat loop (it's the loop that
creates the lag).
Creating an animation like this has some more disadvantages:
- it's 'difficult' to suddenly end the animation (you'd have to kill
all remaining setTimeOuts)
- setTimeOut is an inaccurate way of animating: the position of an
image might be changed twice per cycle or (the other way around) a
position could change once per two cycles

I need to code something that calculates the position of an image
every cycle. To do this I need the deltaT (= milliseconds between
cycles), and for that I need some sort of event (or workaround) that
occurs every cycle (and works both in IE and Mozilla).

I've tried calculating deltaT with a setTimeOut('get DeltaT()',1) and
with the mouseMove event but both seem slightly inaccurate since they
sometimes return deltaT=0.

anybody got a solution?

grtz...

Ron

Jul 20 '05 #1
1 6619
On Sun, 19 Oct 2003 11:00:43 GMT
as**@asdf.as (Brainless) wrote:
<snip>
Based on your explanation I can't figure out exactly how you are
approaching animation. But I suspect that you need to explore
setInterval() rather than setTimer(). I precalculate positions and build
all frames in an animation first, then just let the timer interrupt
drive the iteration of frames. I use a separate timer for each
concurrently running animation.
var cur = 0;
var interval_ID = false;
var isRunning = false;

this.SingleStep Forward = function() {
if(isRunning) this.Stop();
frames[cur].hide();
cur = (cur + 1) % frames.length;
frames[cur].show();
};

this.SingleStep Backward = function() {
if(isRunning) this.Stop();
frames[cur].hide();
cur = (cur + frames.length - 1) % frames.length;
frames[cur].show();
};

this.Stop = function(){
//if (inHarness) tprint(this.nam e + ".Stop()");
if (interval_ID) {
window.clearInt erval(interval_ ID);
};
isRunning = false;
};

this.Run = function() {
if(isRunning) {
this.Stop;
return;
};
isRunning = true;
interval_ID = window.setInter val(this.OnCloc kTick,
this.interval);
};

this.OnClockTic k = function() {
if(isRunning) {
if(frames[cur].waitCnt <= 0) { //if not waiting...
frames[cur].hide(); // hide what is showing
cur = (cur + 1) % frames.length; // calc next
frames[cur].show(); // show next
frames[cur].waitCnt = frames[cur].duration - 1; // set
next wait

}else{ // ignore tick if waiting
frames[cur].waitCnt--;
};
}else{
this.Stop;
};
};

--
Life is an offensive, directed against the repetitious mechanism of the
Universe.
--Alfred North Whitehead (1861-1947)
Jul 20 '05 #2

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

Similar topics

3
4491
by: Dica | last post by:
this works: document.all.style.visibility = 'hidden'; this doesn't setTimeout("document.all.style.visibility = 'hidden'",1000); looks like sResponseDivID isn't recognized. what's the problem? tks
1
1628
by: Better but still clumpsy | last post by:
Hi, I have a script that is looping like this : for (i=0;i<100;i++) { do 1 do 2 display setTimeout("timer",1000);
6
2253
by: Brent | last post by:
Is there any obvious reason why there's no delay in the execution of setting the id.style.display when this function gets called? function Hide(divId,timeout) { var id = document.getElementById(divId); setTimeout(id.style.display = 'none',timeout); } Thanks for any help.
12
5556
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. Foo = function(type) { this.num = 0; this.type = type this.trigger(); } Foo.prototype.trigger = function() {
4
5234
by: E | last post by:
I am having trouble with setTimeout working on a second call to the setTimeout function from a second page which is an html page. Here is the scenario. I have a web page and onload it calls a javascript function which calls setTimeout and will process a second javascript function "Warn" just before the session expires. The Warn function displays an html page with a button. A second timer is started to cause the html page to close...
18
9821
by: barry | last post by:
I'm having a problem creating a delay before each list item gets moved ( http://www.polisource.com/PublicMisc/list-splitter-timeout-bug.html ). Choose any number of columns, vertical layout, and view as a web page. They'll be a small delay before the entire bunch of list items converts from left-to-right to top-to-bottom order. I expected a delay before each item is moved. It looks like I have to flush the buffer to get setTimeout to work,...
15
3796
by: nikki_herring | last post by:
I am using setTimeout( ) to continuously call a function that randomly rotates/displays 2 images on a page. The part I need help with is the second image should rotate 3 seconds after the first image rotates. I cannot figure out how to accomplish the 3 second delay. My code is pasted below: function randPic(){ randPic1(); randPic2();
1
14047
by: alex.malgaroli | last post by:
Hi all. I didn't find anything on the web regarding this different behaviour I found in Firefox (v. 2) and IE (v. 6), so I'm posting it here, maybe someone will benefit from this. I have a function in a javascript object like this: function MyObject.prototype = { myvar = "This is myvar"; myfunction(myarg) {
18
15928
by: Csaba Gabor | last post by:
Is there a straightforward way of implementing a PHP equivalent to window.setTimeout? In a javascript web app, it's often the case that things are done on an event driven basis. For example, html elements might have things like onclick="buttonClicked()" to indicate that the function buttonClicked should be run when that element is clicked. The analogue can be done in PHP (on Windows) using com_event_sink. In other words, you can...
1
9537
by: bizt | last post by:
Hi, I have a process where every so often I refresh a table's data using a setTimeout() .. and when its no longer needed, a clearTimeout(). The following is a simple example of how this is done: var goMenuTimeout = null; function LoadMenu() { // cancel any repeat actions
0
9621
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...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9914
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
8937
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
6717
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
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
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.