A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: accelerate

  1. #1
    Junior Member
    Join Date
    Mar 2002
    Posts
    6
    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

  2. #2
    Senior Member RazoRmedia's Avatar
    Join Date
    Oct 2000
    Location
    UK
    Posts
    3,016
    wh has a great threadon dynamic tweening here

  3. #3
    Senior Member RazoRmedia's Avatar
    Join Date
    Oct 2000
    Location
    UK
    Posts
    3,016
    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);
    }

  4. #4
    Junior Member
    Join Date
    Mar 2002
    Posts
    6
    Do I need a frame action for this code?

  5. #5
    Senior Member RazoRmedia's Avatar
    Join Date
    Oct 2000
    Location
    UK
    Posts
    3,016
    No, simply create a movieclip, right click on it, choose actions and then paste one of the functions shown above.

  6. #6
    official system error
    Join Date
    Dec 2000
    Location
    Italy
    Posts
    899
    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!!!

  7. #7
    Senior Member RazoRmedia's Avatar
    Join Date
    Oct 2000
    Location
    UK
    Posts
    3,016
    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

  8. #8
    Opal Technologies aqeel's Avatar
    Join Date
    Apr 2001
    Location
    England
    Posts
    267

    Wink

    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center