-
I am trying to accelerate an movie clip in Flash. I know about easing but want more control going from one point and accelerating then decelerating to another. I would like to enter the speed and pace of the object. are there any actionscripts for this?
Trying to create a flash horse race with speed and pace where horses over take and fade from certain points around the track....
Thanks
-
Senior Member
wh has a great threadon dynamic tweening here
-
Senior Member
Robert Penner is using complicated functions in that wh thread, heres a simplified approach:
try this:
decceleration:
Code:
onClipEvent (load) {
function deccel (finalX) {
distance = finalX-_x;
_x += distance/4;
}
}
onClipEvent (enterFrame) {
this.deccel(400);
}
acceleration:
Code:
onClipEvent (load) {
function accel (finalX) {
distance = finalX-_x;
if (distance > 0) {
_x += ( _x * .4) ;
}
}
}
onClipEvent (enterFrame) {
this.accel(400);
}
elastic effect:
Code:
onClipEvent (load) {
function accel (finalX) {
distance = finalX-_x;
_x += distance -( _x * .4) ;
}
}
onClipEvent (enterFrame) {
this.accel(400);
}
-
Do I need a frame action for this code?
-
Senior Member
No, simply create a movieclip, right click on it, choose actions and then paste one of the functions shown above.
-
ok, I always used Zeno's paradox to make deceleration and worked great for mouse trailer things
so now that's what I want to be explained about your code:
onClipEvent (load) {
function accel (finalX) {
distance = finalX-_x;
if (distance > 0) {
_x += ( _x * .4) ;
}
}
}
onClipEvent (enterFrame) {
this.accel(400);
}
1-function is a subprogram right? like in C++?
so finalX it's its parameter right?
2-accel calls itself inside itself so it's a recoursive function (i hope "recoursive" is right) so in that case it calls itself substracting to finalX the _x value of the movie clip right?
3-what's the difference between load and enterframe in that case? doesn't both code lines start at the beginning?
or is: load = initialization
enterframe = "when a movie clip is on the stage" so then...
Thank you in advance, i really needed that!!!
-
Senior Member
onClipEvent (load) {
function accel (finalX) {
distance = finalX-_x;
if (distance > 0) {
_x += ( _x * .4) ;
}
}
}
onClipEvent (enterFrame) {
this.accel(400);
}
1-function is a subprogram right? like in C++?
so finalX it's its parameter right?
the function name is accel, the parameter is 'finalX'. click here for basic functions tutorial.
2-accel calls itself inside itself so it's a recoursive function (i hope "recoursive" is right) so in that case it calls itself substracting to finalX the _x value of the movie clip right?
It doesn't call itself, its not a recursive function. The function is highlighted in bold above.
3-what's the difference between load and enterframe in that case? doesn't both code lines start at the beginning?
or is: load = initialization
enterframe = "when a movie clip is on the stage" so then...
thats about right yes, the function is set up when the mc loads whereas the rest of the code gets triggered on every single frame, so if your frame rate is 10 fps, the code gets triggered every tenth of a second.
Thank you in advance, i really needed that!!!
no problem chief
-
Opal Technologies
put this code on the movie clip u want to accelerate
onClipEvent (load) {
var s =_x;
}
onClipEvent (enterFrame) {
myspeed = (_x - s)/5;
_x -= myspeed;
}
to accelerate the movie clip to desired position just use
on (release) {
_root.movie_clip_name.s = desired_position;
}
i think its the simplest
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|