PDA

View Full Version : Make animation slow and smooth


rmedek
08-10-2008, 10:42 PM
I am using a script I found in a tutorial online to move an object around randomly inside the boundaries of a container. The script is applied to a movie clip (the object) in the only frame of the .fla file:

onClipEvent (load) {

//data you may want to change
width = 60;
height = 20;
speed = 1;

//initial positions
x = this._x=Math.random()*width;
y = this._y=Math.random()*height;
x_new = Math.random()*width;
y_new = Math.random()*height;
}

onClipEvent (enterFrame) {

//x movement
if (x_new>this._x) {
sign_x = 1;
} else {
sign_x = -1;
}
dx = Math.abs(x_new-this._x);
if ((dx>speed) || (dx<-speed)) {
this._x += sign_x*speed;
} else {
x_new = Math.random()*width;
}

//y movement
if (y_new>this._y) {
sign_y = 1;
} else {
sign_y = -1;
}
dy = Math.abs(y_new-this._y);
if ((dy>speed) || (dy<-speed)) {
this._y += sign_y*speed;
} else {
y_new = Math.random()*height;
}
}

So far so good, but the trick is I'd like the object to move slower. The speed is controlled via the variable "speed," but anything lower than "1" makes the animation very jerky. I've tried adjusting the numbers along with the frame rate and I can't figure out a way to smooth out the animation. Any ideas?

jschumann
08-12-2008, 10:43 PM
I tested your code and changed your speed variable to .5. I also changed the default frame rate of the swf to 30 fps. The animation seemed to move very smoothly. Try those settings and see if that gives you the correct results.

rmedek
08-13-2008, 07:06 AM
Thanks for the reply jschumann…I tried your combo but I still felt the animation was a bit jerkier than I would like, plus not quite as slow as I would want it. At 1 and 25 the movement is very smooth, just not slow enough…can't figure out a way to give slower pixel-by-pixel movement the appearance of something less "stepped."

In the meantime I ended up using motion paths and recreating the movement manually rather than at random. It's a workaround that lets me get a bit more horizontal motion over frames, making it look a little smoother.

gnomeontherun
08-13-2008, 05:50 PM
I think the problem is that each frame the animation will jump _X_ number of pixels. You can try to soften it with some motion tweens, but those are for having the motion do some elastic type movements (easeIn, etc). Perhaps you could change the size of the animation? Or perhaps you can resize the containing moveclip to be smaller, so the animation appears smoother? Also something round will appear smoother than moving a square or rigid box.