Jump to content
Search Community

TimelineLite.insertMultiple

stratboy test
Moderator Tag

Recommended Posts

Hi again.

 

I've got a class, with a tmLite:TimelineLite prop.

In a method I call this to show my elements:

 

tmLite = new TimelineLite();
tmLite.insertMultiple([new TweenLite(bg,0.5,{ alpha:1 }),
new TweenLite(thumb3,0.5,{ y:37 }),
new TweenLite(thumb2,0.5,{ y:37 }),
new TweenLite(thumb1,0.5,{ y:37 }),
new TweenLite(smallImg,0.5,{ x:23 }),
new TweenLite(dataBox,0.5,{ x:23 }),
new TweenLite(closeButton,0.5,{ x:stage.stageWidth-closeButton.width-30 }),
new TweenLite(bigImg,0.5,{ alpha:1 }),
],0,TweenAlign.START, 0.1);

 

So far, so good, all fine. then, in another method, i tried to do this, to hide them all:

 

tmLite.insertMultiple([new TweenLite(bigImg,0.5,{ alpha:0 }),
new TweenLite(closeButton,0.5,{ x:stage.stageWidth+30 }),
new TweenLite(dataBox,0.5,{ x:-dataBox.width }),
new TweenLite(smallImg,0.5,{ x:-smallImg.width }),
new TweenLite(thumb1,0.5,{ y:-thumb1.height }),
new TweenLite(thumb2,0.5,{ y:-thumb2.height }),
new TweenLite(thumb3,0.5,{ y:-thumb3.height }),
new TweenLite(bg,0.5,{ alpha:0 })],0,TweenAlign.START, 0.1);

 

But nothing happened. I also tried Timelinelite.clear() before, but again, nothing happened. So I ended up reassigning tmLite to a new TimelineLite() and all worked fine. But I'd like to better understand why I can't do it the other way. :)

Link to comment
Share on other sites

I see two potential problems.

 

1) you've got conflicting tweens. You inserted all your stuff at the 0 time (the beginning). So you've got stuff tweening to various y positions at the same time.

 

2) I'm not sure how you're playing the timeline, but I suspect you're misunderstanding the timing works in a TimelineLite/Max. See viewtopic.php?f=1&t=2324&p=8709#p8709 for an explanation.

 

Also, I'd highly recommend watching the video at http://www.greensock.com/timeline-basics/

Link to comment
Share on other sites

Yes I know that video, really good.

 

I've just read the topic. I'm still not sure. So, when the first TimelineLite usage ends (when all the first opening tweens are complete), does the virtual playhead continue to play? Or it just gets automatically paused at 0.5 (the duration of the tweens)?

 

Anyway, could this be a solution for the closing tweens? :

 

1. pause my tmLite

2. clear it

3. reposition the virtual playhead to zero

4. insert the closing tweens

5. play

 

Or maybe this? :

 

1. pause

2. insert the closing tweens at 0.5 time (the duration of the opening tweens)

3. play from 0.5

Link to comment
Share on other sites

When all your opening tweens complete, unless tmLite is a local variable it remains stopped at end of it's playhead.

The reason insertMultiple() does nothing for you is because the tween has already reached the end of it's timeline.

I would either use tmLite.reverse(), or create a new tmLite instance, (i.e. tmLite = new TimelineLite();)

Link to comment
Share on other sites

reverse() is simply fantastic BUT I can't use it here, because I need to hide elements by moving them off screen, and the site is fullscreen, so if one for example enlarge the browser window before hiding them, some of them (right/bottom items) don't reach the off-screen position. I need to specify the destination explicitly.

 

The other solution you're telling, well, it's just the one I adopted. All the thread is just about how (if possible) to avoid it and reusing the original instance.

 

So do you think that none of the 2 solutions (the 5 and 3 points) I asked are fine for the task?

Link to comment
Share on other sites

So do you think that none of the 2 solutions (the 5 and 3 points) I asked are fine for the task?

 

Sure, either of those should work, but like TronicVolta advised, it'd probably be better/cleaner to just create another instance. There has been a lot of hype on the web about improving performance by recycling objects and object pooling, but frankly it's mostly hype. The overhead involved in cleaning instances and managing pools often costs more than just creating another instance, so you can actually get worse performance by trying to recycle.

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