Jump to content
Search Community

set pause of Tween within Timeline cause startTime reset

kittichai test
Moderator Tag

Recommended Posts

Here's the sample code:

 

			
timeline1 = new TimelineMax();
var tween1:TweenMax = new TweenMax(spriteGreen,0.0001, {x:600, ease:Linear.easeIn, paused:true});
timeline1.insert(tween1,1.5);
trace(tween1.startTime);
tween1.paused = false;
trace(tween1.startTime);

 

The result of running the above code will be:

1.5
0

1) Why is that unpausing tween within timeline change its startTime?

 

 

2) I recall you mentioned that it is unnecessary to assigned paused:true at TweenMax constructor. But, how can I ensure that the Tween will not finish executing before adding to timeline?

 

I have to assign the above duration of 0.00001 because I need to hook onComplete function. Which, if duration of Tween is 0, the onComplete will not work correctly.

 

Please give me some fix soon.

Link to comment
Share on other sites

1) Why is that unpausing tween within timeline change its startTime?

Unpausing a tween is the same thing as playing it. So if its parent timeline's currentTime is 0 and you unpause your tween, it will adjust its position accordingly so that the startTime is at 0. This is all normal.

 

2) I recall you mentioned that it is unnecessary to assigned paused:true at TweenMax constructor. But, how can I ensure that the Tween will not finish executing before adding to timeline?

 

I have to assign the above duration of 0.00001 because I need to hook onComplete function. Which, if duration of Tween is 0, the onComplete will not work correctly.

 

The GreenSock tweening platform is one of the few out there that uses a completely synchronized timing mechanism, meaning that it is protected against time drifting that can occur when the CPU gets bogged down. So if you loop through and create 1,000,000 tweens on a single frame, for example, they would all have exactly the same start time even if there was a 5-second gap between when the first one and the 1,000,000th one was instantiated in the loop. Consequently, you don't need to worry about your 0.00001-second tween rendering before it gets added to your TimelineLite. By default, tweens never render anyway until the next ENTER_FRAME event fires.

 

Does that answer your question?

 

Oh, and by the way, you can insert a zero-duration tween with an onComplete and if you don't want it to render immediately, simply set immediateRender:false on the tween. Like:

timeline1.insert(new TweenMax(myFunction, 0, {onComplete:myFunction, immediateRender:false}), 1.5);

 

In TimelineMax, there's an addCallback() method that can do the same thing with less code.

Link to comment
Share on other sites

YEah! That's cool features. Thanks for your quick reply.

Anyway, just to be sure:

3) Do I have to disable onEnterFrame myself or Greensock platform preventing it for me? If I have to like disable frame rendering, add tween, then enable it again... what would be the line of code needed to disable it?

4) The thing with my 0.0001 duration Tween is, this Tween can be play either forward or reverse, and I want to hook events when it "start" and "complete" on both directions (). And... you didn't have onReverseStart for me to hook. So I have to hook onUpdate instead. I will not be able to distinguish them any otherwise.

Link to comment
Share on other sites

I don't think so actually because there are practical benefits to all the others, but I cannot think of one for a startReverse. Why wouldn't you just run your code right before calling reverse()? Like:

...do stuff here...
myTween.reverse();

 

One of my primary goals with the tweening platform is keeping file size low and performance maximized while providing tons of practical conveniences and functionality. If you could help me understand the significant practical benefit of adding an onStartReverse, I'd gladly consider adding it.

Link to comment
Share on other sites

  • 10 months later...

If you could help me understand the significant practical benefit of adding an onStartReverse, I'd gladly consider adding it.

 

One of the ways I would use it is when tweening buttons in and out. Basically I have added some buttons to a view's animate In TimelineMax (on Complete they become active), and I was hoping to use it to switch off/deactivate all the buttons when told to start the reverse animation.

 

Would this be a viable reason to add it in?

Link to comment
Share on other sites

One of the ways I would use it is when tweening buttons in and out. Basically I have added some buttons to a view's animate In TimelineMax (on Complete they become active), and I was hoping to use it to switch off/deactivate all the buttons when told to start the reverse animation.

 

Would this be a viable reason to add it in?

No, not really because in the example you gave, the tween wouldn't actually be reversed - its parent TimelineMax would be. It can be a little tricky when you've got nested things, like a reversed tween that's nested in a reversed TimelineMax would appear to play forwards. See what I mean? Since onReversed* only play when the tween/timeline is actually reversed (its "reversed" property is true), it wouldn't get fired in the example you gave. You can, however, use TimelineMax's addCallback() method to put a method call at a particular time on the timeline which gets triggered regardless of whether or not the TimelineMax is reversed. So just append() your tween and then myTimeline.addCallback(myFunction, myTimeline.duration); to put it immediately after the tween. That'll get you the result you're after.

Link to comment
Share on other sites

One of the ways I would use it is when tweening buttons in and out. Basically I have added some buttons to a view's animate In TimelineMax (on Complete they become active), and I was hoping to use it to switch off/deactivate all the buttons when told to start the reverse animation.

 

Would this be a viable reason to add it in?

No, not really because in the example you gave, the tween wouldn't actually be reversed - its parent TimelineMax would be. It can be a little tricky when you've got nested things, like a reversed tween that's nested in a reversed TimelineMax would appear to play forwards. See what I mean? Since onReversed* only play when the tween/timeline is actually reversed (its "reversed" property is true), it wouldn't get fired in the example you gave. You can, however, use TimelineMax's addCallback() method to put a method call at a particular time on the timeline which gets triggered regardless of whether or not the TimelineMax is reversed. So just append() your tween and then myTimeline.addCallback(myFunction, myTimeline.duration); to put it immediately after the tween. That'll get you the result you're after.

 

Ah, ok I see. Thanks :)

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...