Pardon? Is there any other sort of animation?
The other kind is frame-based.
you have distance and time and number of frames.
setInterval(f, 20) the function f doesn't fire every 20 ms. It depends
how long f takes, among other things, before f can fire again.
If distance-per-frame is a constant, then total time will increase,
making the animation time vary greatly between browsers. This is frame-
based animation.
I check the time in each call to _playFrame(). Distance is calculated
as a result of elapsed/total. distance = [0-1]. distance is elapsed =
new Date-startTime; distance = elapsed/totalTime. That's time based.
The animation finishes in a certain time. It can go over totalTime,
but not by a large amount; maybe 10-20ms at most. When that happens,
the animation is ended with distance = 1. In Time based animation, the
number of frames varies. But if there's double threads, the frame rate
increases. In webkit and IE, the animation is super smooth with the
doubled frame rate. Webkit is fine with up to 5 timers (setInterval),
actually.
Distance is calculated on a rationalValue (or floating point position
[0-1]). The "property" is always a number from [0-1]. In a 2 sec
animation, if 1 sec had elapsed, then the position would be 0.5.
It matters not how far the object is moved but how many steps the motion
takes. The more steps, the shorter each interval, the more calls are to be
performed, the greater is the CPU load, and the more likely is that your
animation does not run smoothly because either your timers accumulate or the
layout engine cannot handle it anymore. Accumulation is more likely when
you use window.setInterval() instead of window.setTimeout(). I have
explained why a few months ago; search the newsgroup.
The search feature on Google Groups does not work at all in any
browser for any Google username on this computer; I think it has to do
with a language preference cookie somewhere. Even when I click
"without the language restriction" link, it returns 0 results.
This is not going to work properly. Consider the timeline here
(`*' denotes a call):
intv1 * * * * * *
intv2 | * | * | * | *
steps | | | | | | | |
|----+----+----+----+----+----+----+----+----+----+----+----+---->
0 10 20 30 40 50 60 70 80 90 100 110 120 ms
Meaning that every 60 ms (60 is the LCM of 20 and 30) the scheduler will
have to handle two calls. Since that is not going to happen as the
implementation is single-threaded indeed, the second call will be slightly
delayed. Nevertheless, at almost the same time you do the animation, moving
the object virtually twice per each step. Also note that the second
window.setInterval() call happens shortly after the first one, and not
simultaneously, and that 10 ms is the minimum timeout that Mozilla on x86
will handle. So the delay that can be expected on interval is increased by
at least that time span (consider external interference). A "jumping"
animation in place of a smooth one becomes more and more likely:
intv1 * * * * * *
intv2 | * | | * | * | | *
steps | | | | | | | | | |
|----+----+----+----+----+----+----+----+----+----+----+----+---->
0 10 20 30 40 50 60 70 80 90 100 110 120 ms
The jumping I get i caused by mozilla being a CPU hog for whatever
else it's doing. Adding more timers hogs more CPUs, which contributes
to jumpiness in a different way.
If I change the second timer so they're both 20ms. I don't know if
that means the other time will have to "yeild" less or not. It could
be that the timers have to compete instead of weave and that's not
determinable. Even if the LCM was high (lets say I picked 45 for the
second setInterval, LCM would be 180); well, I still get jerky
behavior. Even with only 1 timer. It's mozilla.