Jump to content
Search Community

How to determine the position of while tweening is in progress and calulate total tweening time

blissville test
Moderator Tag

Recommended Posts

Hello,

I have written this code 

mc.x = 40;
mc.y = 40;
var myTween:TweenMax = new TweenMax (mc, speed, {paused:true, bezier:{curviness:0.4, autoRotate:true, values:[{x:234, y:120}, {x:90, y:120}, {x:90, y:190}]}});

Now, I want to pause this tween at some point, resume it and calculate the total time it took for it to finish. Also, am interested in knowing the exact position of the movieclip while tween is in progress. for example, from the initial x coordinate which is 40, I want to know when it gets to 67 for example then pause the tween and resume it after 5 seconds. then calculate the total time the tween started to when it got paused and resumed until it is completed.

Link to comment
Share on other sites

You can use an onUpdate callback to run whatever logic you want. An onUpdate gets called every time the tween updates (every "tick"). Keep in mind, however, that the values won't always be perfect integers (they'll have decimals most likely) during the tween, so don't just check to see if x === 67. 

 

Example:

var myTween:TweenMax = new TweenMax(mc, speed, {
    bezier:{curviness:0.4, autoRotate:true, values:[{x:234, y:120}, {x:90, y:120}, {x:90, y:190}]},
    onUpdate:function() {
        if (mc.x <= 67) {
            //do stuff
        }
    }
});

But beware that bezier tweens can hit the same value many times (like think of the letter "S" - it travels past the same "x" value 3 times)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...