Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
pablolo

Random Timeline

Recommended Posts

Anyone know an easy wat to Randomize a TimelineMax?

 

I want to append several TweenMax instances and depending on user behavior, play the timeline with the instances in a different (random) order

 

For example, first plays it normally:

 

var timeline:TimelineMax = new TimelineMax({repeat:0});

//

timeline.append( TweenMax.from(mainMC1, 1, {alpha:0, blurFilter:{blurX:100, blurY:100}})-0.5);

timeline.append( TweenMax.from(mainMC2, 1, {alpha:0, scaleX:0.1}), -0.5);

timeline.append( TweenMax.from(mainMC3, 1, {alpha:0, scaleY:0.1}), -0.5);

timeline.append( TweenMax.from(mainMC4, 1, {alpha:0}), -0.5);

timeline.append( TweenMax.from(mainMC5, 1, {alpha:0}), -0.5);

 

//

 

and then restart with

timeline.invalidate();

timeline.restart();

 

and then "randomize" the appends is if it was like this:

 

timeline.append( TweenMax.from(mainMC5, 1, {alpha:0}), -0.5);

timeline.append( TweenMax.from(mainMC2, 1, {alpha:0, scaleX:0.1}), -0.5);

timeline.append( TweenMax.from(mainMC1, 1, {alpha:0, blurFilter:{blurX:100, blurY:100}})-0.5);

timeline.append( TweenMax.from(mainMC3, 1, {alpha:0, scaleY:0.1}), -0.5);

timeline.append( TweenMax.from(mainMC4, 1, {alpha:0}), -0.5);

 

any ideas?

Link to post
Share on other sites

hmmm, I've never done that before and it could take some experimenting.

 

I would start by adding all my tweens to an array, then randomize/shuffle the array, then loop through the array and append the tweens in the order that they appear in the shuffled array.

 

there could very well be something very wrong with this idea, but it might be worth a try. If I have time later I might just toy around with it.

Link to post
Share on other sites

Thank you very much for the reply, Carl.

 

I thought about that, but I am doing an app for iPad, which means that optimization is like the MOST important thing and iterating back and fourth trough an array doesnt sound very optimized.

At the same time I know how you guys here are optimization ninjas, so any clue on how to do it in the best way would be awesome.

 

Thank you again anyways.

Link to post
Share on other sites

If the tweens themselves are the same and you're just trying to shuffle their order around in the TimelineMax, this is probably the most efficient way, although I doubt you'd see any major improvement compared to just creating new timeline and tween instances each time:

 

var timeline:TimelineMax = new TimelineMax();

timeline.append( TweenMax.from(mainMC1, 1, {alpha:0, blurFilter:{blurX:100, blurY:100}}), -0.5);
timeline.append( TweenMax.from(mainMC2, 1, {alpha:0, scaleX:0.1}), -0.5);
timeline.append( TweenMax.from(mainMC3, 1, {alpha:0, scaleY:0.1}), -0.5);
timeline.append( TweenMax.from(mainMC4, 1, {alpha:0}), -0.5);
timeline.append( TweenMax.from(mainMC5, 1, {alpha:0}), -0.5);

//then call this whenever you want to randomize
function randomizeTweens():void {
var tweens:Array = timeline.getChildren();
var index:int;
var time:Number = 0;
var i:int = tweens.length;
while (--i > -1) {
	index = int((i + 1) * Math.random());
	tweens[index].startTime = time;
	tweens.splice(index, 1);
	time += 0.5;
}
timeline.restart();
}

 

Does that help?

Link to post
Share on other sites

thanks a lot green

 

did you try it?

I have tried for a few moments without success. Not working.

I will try harder later.

Link to post
Share on other sites

Yep, I tried it and it worked perfectly for me.

Link to post
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.

×