A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Movement with easing

  1. #1
    Member
    Join Date
    Mar 2003
    Location
    Sweden
    Posts
    56

    Movement with easing

    In a presentation (Flash MX. Mac) a movie clip shall move from one place to another on the stage with very smooth easing before stopping. I usually do that with a tween on the timeline. But now I would like to get that in a script in a key frame instead on the timeline, for a smother movement, I hope, and I will reuse this many times in the presentation. So now I wonder if someone out there can show me how to write that script, please?

  2. #2
    Space Monkey daarboven's Avatar
    Join Date
    Sep 2001
    Location
    in the basement boiling soap...
    Posts
    217
    calculate the distance between startpoint and targetpoint, then add this distance divided by an easing factor to the current position
    of your mc
    main Timeline:
    code:

    //define values
    //startpoint is whereever you place the moviclip myMC
    startpoint = myMC._x;
    //define a target position
    targetpoint = 220;
    //the easing factor, lower values=faster movement
    easeme = 12;
    //the easing function
    myMC.onEnterFrame = function() {
    //calculate distance
    dist = Math.round(targetpoint-this._x);
    //add distance divided by factor
    this._x += dist/easeme;

    if (dist == 0) {
    //at the position, kill on enterFrame
    trace("here");
    delete this.onEnterFrame;
    }
    };


    :::i am jacks complete lack of surprise:::

  3. #3
    Member
    Join Date
    Mar 2003
    Location
    Sweden
    Posts
    56
    Thanks a lot Daarboven!

  4. #4
    Member
    Join Date
    Apr 2005
    Location
    london, uk
    Posts
    92
    All you need to know about easing equations can be found here:

    http://www.robertpenner.com/easing/

    enjoy!
    DB

  5. #5
    Member
    Join Date
    Mar 2003
    Location
    Sweden
    Posts
    56
    Yes, you are right there is all you need to know. Thank you

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