Hey guys,
How is it that sometimes designers can get the animations to be so freakin smooth. And Im not talking about only smooth on the fastest computers. Somehow they manage to make it their animations run very fluid. Any idea how to do this. I make all of my movies at 30 fps yet i dont seem to get the same kind of movement. Anyhelp would be great.
Thanks
Don
Upload a simple example of something you made that isn't smooth enough.
In general, most of the actionscript based animations I've seen posted on this board tend to use 1 of 4 different styles of movement.
1. Linear movement. This is by far the most common by newbies (cause it's easy to do) and it looks the the jerkiest. Especially when starting and stopping.
_x += k;
(where k is a fixed number).
2. Fractional ease-out. This starts fast but ends up smooth & slow. Often used for alpha fades and slides.
_x += (target-_x)/k;
3. Time-based Ease-in/Ease-out. This starts slow, speeds up and then slows down at the end. A personal favorite of mine, see below.
k = elapsedTime/duration; // k = 0-1
k = k*k*(3-2*k); // apply easing
_x = start + (target - start)*k;
4. Sine wave motion. This performs smooth oscillations or pendulum motions, another favorite of mine.
_x = midPoint + Math.sin(timeValue) * width;
#2 above, is VERY popular on this board. And you'll see numerous examples of it every day.
It suffers from a few problems, which is why I like #3 better.
a. When used to travel a large distance, such as to alpha fade from 0 to 255, it tends to be either fast and choppy or smooth and slow. It's hard to make it fast and smooth. If you plot subsequent values in a program like Excel, you'll see why - small values of K make big jumps at the beginning, and large values of K take a long time to converge.
b. You can't easily predict how long it will take. Increasing K makes it slower, but how much?
c. It's duration is proportional to framerate. Double the framerate, and it's twice as fast. You may like this, but I don't.
d. It never actually reaches the target value - so to get it to stop, you have to add a test to see if it's close to the target value:
dx = (target - _x);
if (Math.abs(dx) < AcceptableMinimum)
{
// stop it
}
else
_x += dx/k;
This is why I prefer method #3. It starts smooth, ends smooth and takes a predictable amount of time, which you can specify in seconds or milliseconds. If you look at my prior posts, you'll see two or three examples of alpha and x tweens that use it.
Good lord,
that was easily the most thorough response I could have ever imagined. Thank you very much. I will study these animation tactics.
Sincerely,
Don Ho
I have a question about number 3:
k = elapsedTime/duration; // k = 0-1
k = k*k*(3-2*k); // apply easing
_x = start + (target - start)*k;
where did the number 3-2 come from. Are they arbitrary? In addition, what is value of elapsedtime and duration. Do you just make it up. Are there certain numbers that typically make up these variables.
Thanks
Don
is a reduction of a common easing equation which I'll look up when I'm near my library (I think I got it out of Foley/Van Damn). It makes the numbers below .5 get smaller and the numbers above .5 get larger. Although I don't recommend futzing with the 3 and the 2, you can apply it twice if you want extra easing.
k=k*k*(3-2*k)
k=k*k*(3-2*k)
It is instructive to see what these equations do in a spreadsheet like Excel.
In one colum enter values going from 0 to 1:
0
.05
.1
.15
.2
.25
.3
etc...
And the next colum over enter the formula:
A1*A1*(3-2*A1)
Then select both columns and make a graph so you can see what the numbers do. The left colum makes a straight line (this is why its called linear motion) and the right column makes an S shaped curve.
Here's a complete example that shows how I get elapsedTime and duration. It assumes the existence of a movieclip called 'mc' and applies easing to the _xscale and _yscale to make a button expand and contract. FLA attached, which uses 24 fps.
Code:
MovieClip.prototype.doTween = function() {
// get elapsed time in milliseconds
var elapsedTime = getTimer()-this.startTime;
// convert to easing ratio 0-1
var k = elapsedTime/this.duration;
if (k>1) {
// are we done yet?
k = 1;
this.onEnterFrame = undefined;
}
// apply easing
k = k*k*(3-2*k);
// apply easing
// perform the tween
this._xscale = this._yscale=this.startS+(this.deltaS*k);
};
MovieClip.prototype.startTween = function(targetScale, seconds) {
// get start time, in milliseconds
this.startTime = getTimer();
// compute duration in milliseconds
this.duration = seconds*1000;
// get start and end values
this.startS = this._xscale;
this.targetS = targetScale;
// compute the difference (the 'delta')
this.deltaS = this.targetS-this.startS;
// begin tweening
this.onEnterFrame = this.doTween;
};
mc.onRollOver = function() {
// expand to 150% over 1.5 seconds
this.startTween(150, 1.5);
};
mc.onRollOut = function() {
// contract to 100% over 0.5 seconds
this.startTween(100, 0.5);
};
Well, when I want to create an easing function, I just use what we have learnt during the math classes.
Since speed is the first derivative of the distance traveled against time, you may "invent" speed functions by looking at the integral of a random function you like most. A quadratic equation is quite good for that, a sine function can also be used (you can use whatever you want). Just integrate, select the interval you like most (the interval is time), and induce a parameter that generates an area (under the speed curve) that suits your distance.
An example of derivation of a quadratic function:
Code:
Lets say we want the movie to move in a time interval of 40 frames (i.e. timeinterval=40):
speed = a(- t^2 + (timeinterval/2)^2)
Integrate the speed function against t (lower bound is -(timeinterval/2) and the upper is timeinterval/2):
distance = a(-((timeinterval/2)^3)/3+(timeinterval/2)^2×timeinterval/2)-
a(-((-timeinterval/2)^3)/3+(timeinterval/2)^2×-timeinterval/2)
If you simplify this, you get:
distance = (a×timeinterval^3)/6
But you know the distance - say distance is 500 (pixels), and can now calculate the value of parameter a:
a = distance×6/timeinterval^3
Now we have a function of speed:
speed = distance × 6 / timeinterval^3(-t^2 + (timeinterval/2)^2)
That's the derivation of an example function. If you don't see the power of this method... well here we go:
1. you may create functions that dont ease only in a linear direction, but may change the direction of movement according to any function (say speed becomes negative, or jups up a luttle and then back down...)
2. you may produce virtually any easing function
3. you may practice your math and discover not to create speed functions but displacement functions - which are faster and more accurate - they do not involve intergration (rather trivial actually)
The disadvantages of the method:
1. inaccurate
I think you're asking if you can use it on a script which is on the main timeline. Yes you can. Let's say there is a movieclip called 'mc'. Here is a more fleshed out version of that script.
I guess I did not explain what I am trying to do well enough. If I have animation on the main timeline with no movieclips, can I still apply script 2 to the main timeline?
"My boss sits and watches TV in a hot dog suit and I think he might be a moron."
movieclip only, the scripting has to be able to identify what it is acting on - an object, you have to turn something into an object before you can use scripting on it (in general).
for example if you're gonna move a start 200 to the right how do you plan on identifying the star in the programming if it's just a shape that you drew?
Upload a simple example of something you made that isn't smooth enough.
In general, most of the actionscript based animations I've seen posted on this board tend to use 1 of 4 different styles of movement.
1. Linear movement. This is by far the most common by newbies (cause it's easy to do) and it looks the the jerkiest. Especially when starting and stopping.
_x += k;
(where k is a fixed number).
I am trying to create a smooth linear animation; and, I was wondering if the linear equation would be smooth instead of jerky or did I misunderstand Jbum's statement.
Thanks,
"My boss sits and watches TV in a hot dog suit and I think he might be a moron."
what if I wanted this MC to move at a steady pace,
then once it reached its destination ..
maybe faded out? .. or start back at the begining?
is that possible?
thanks,
-dan
Originally Posted by jbum
I think you're asking if you can use it on a script which is on the main timeline. Yes you can. Let's say there is a movieclip called 'mc'. Here is a more fleshed out version of that script.