3 Part Video Series on Bubbles with TimelineMax

by carl schooff on December 7, 2010 · View Comments

in GreenSock Tweening Platform Tips

This movie requires Flash Player 9

So here it is. A step by step walkthrough of using TimelineMax to control the sequenced animation of hundreds of items. Here I’m using bubbles, but this code can be easily adapted for twinkling stars, falling snow, or leaping frogs. If you watch all three parts I guarantee you will learn a trick or 2 about using TimelineMax. This is really the stuff that matters, once you can understand the basic concepts like nesting timelines and using append(), insert(), prepend(), restart(), pause() etc. You really have what it takes to make amazing things. To top it all off you can rewind and pause a zillion things happening at once. sheesh.

Okay folks here we go.

Part 1: Setting up the file and basic animation

Featured AS3 Code:

        //create new Timeline for each bubble's animation properties
	var nestedTl:TimelineMax = new TimelineMax();
	//set random speed value between 1 and 3 seconds (also used for scaling)
	var speed:Number = randomRange(1,3);

	//bubble up
	nestedTl.insert(TweenMax.to(bubble, speed, {y:-40, ease:Quad.easeIn}));
        //bubble fade and grow
	nestedTl.insert(TweenMax.to(bubble, .5, {scaleX:speed, scaleY:speed, alpha:randomRange(.5, 1)}));

	//add each new bubble timeline with a negative offset.
        //my explanation in the video isn't entirely accurate but it will do.
	tl.append(nestedTl, speed*-.89);

Part 2: Random Wiggles in 2 Directions

Featured AS3 Code:

        // how far to wiggle
        var wiggle:Number = randomRange(25,50);
	// set wiggle to + or - value
	wiggle = Math.random() > .5 ? wiggle : -wiggle;

       ....
     //make the wiggle repeat a random number of times. make sure duration of single wiggle is 25% of speed going up.
     nestedTl.insert(TweenMax.to(bubble, speed*.25, {x:String(wiggle), repeat:randomRange(1,4), yoyo:true}));

note: writing wiggle = Math.random() > .5 ? wiggle : -wiggle; is the same as

if(Math.random() > .5) {
     wiggle = wiggle
} else {
 wiggle = -wiggle
}

or even better, but too late

if(Math.random < .5) {wiggle *= -1}

Part 3 Play, Pause, and Rewind your particles

Featured AS3 Code:

       function playTl(e:MouseEvent):void {
	// if timeline done playing then restart or else play from wherever the playhead is.
	if(tl.currentProgress == 1){
		tl.restart();
		}else{
			 tl.play();
			}
}

function pauseTl(e:MouseEvent):void {
	tl.pause();
}

function reverseTl(e:MouseEvent):void {
	tl.reverse();
}

Download Flash CS4 Files

AS3
Bubble Files

AS2
bubbles_as2_cs4
Whew.

Post to Twitter Post to Facebook

  • http://www.snorkl.tv/2010/12/timelinemax-bubbles-play-pause-and-rewind-particle-systems/ make bubbles with flash and timelinemax and as3

    [...] don’t have time to get into a video on this. EDIT: 3 VIDEOS TO WATCH HERE: This is more of a sneak-peak at what is to come. There is soooo much cool stuff to cover with [...]

  • Cor

    Thank you for the nice tutorial!

    Is it possible to set the bubbles as mask for a background image so only the part where the bubble is, is visible?

  • http://www.snorkl.tv/ carl schooff

    Hi Cor,

    yup check it out here: http://www.snorkl.tv/dev/bubbl…/
    you can download files here: http://www.snorkl.tv/dev/bubbl…

    basically what you do is create a movieclip to put all your bubbles in
    then you tell some other movieclip to use your bubbleHolder as its mask.

    like this:

    //clip to be masked
    bg.cacheAsBitmap = true;

    //clip to use as mask
    var bubbleHolder:MovieClip = new MovieClip();

    addChild(bubbleHolder);

    bubbleHolder.cacheAsBitmap = true;
    bg.mask = bubbleHolder;

    inside the createBubble function you then add the bubbles to bubbleHolder like

    bubbleHolder.addChild(bubble)

  • Cor

    Thanks Carl!!
    Damn. The new MovieClip as holder of all the bubbles is the trick.
    I should have come up with that my self.
    I am stupid… :-( (

    Thanks again and for the very good tutorials!

  • Guerra

    you killed it again homie!
    timelined bubbles for realz yo!

  • http://www.snorkl.tv/2011/04/fun-and-quick-timelinemax-effect-cluster-bomb/ Fun and Quick TimelineMax Effect: Cluster Bomb

    [...] you need to see the basic TimelineMax concepts explained in more detail, check out my series on TimelineMax Bubbles This movie requires Flash Player 9 [...]

  • http://profiles.google.com/marcelmarnix Marcel Marnix

    Thanks for all the tuts

  • Cor

    Thank you Carl!!!!!!!

  • http://www.snorkl.tv/ carl schooff

    no problem. glad you got something out of it!

  • Sol

    Hi Carl, amazing work on this tut. Is it possible to have just the first part in as2 pretty please, You’ll be saving a massive heartache.

    Sol

  • http://www.snorkl.tv/ carl schooff

    I added an as2 file of the whole thing

  • Sol

    Carl, you are the best. Gracias

  • Joanne

    You’re funny.! Love it..! Makes tutorial more fun and enjoyable.

  • http://www.snorkl.tv/ carl schooff

    thanks Joanne. glad you found some humor in it. you are part of a very small minority:)

    best,

    Carl

  • http://profile.yahoo.com/KNHSUWVMVYVLIHUADDZVGQ7GEE Anonymous

    On your TimelineLIte Video the Ulitimate Starter Guide….how did you animate those stars? I’m looking for something just like that. I thought maybe this above video would guide me but not quite. Thanks! 

blog comments powered by Disqus

Previous post:

Next post: