473,396 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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('getDeltaT()',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 6585
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.SingleStepForward = function() {
if(isRunning) this.Stop();
frames[cur].hide();
cur = (cur + 1) % frames.length;
frames[cur].show();
};

this.SingleStepBackward = 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.name + ".Stop()");
if (interval_ID) {
window.clearInterval(interval_ID);
};
isRunning = false;
};

this.Run = function() {
if(isRunning) {
this.Stop;
return;
};
isRunning = true;
interval_ID = window.setInterval(this.OnClockTick,
this.interval);
};

this.OnClockTick = 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
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?...
1
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
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 =...
12
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. ...
4
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...
18
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...
15
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...
1
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...
18
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,...
1
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.