A realistic rising air bubbles animation with AS (f5)

hello all…

This is what I am trying to do:

I want to make a light animation where air bubbles come out of a bucket (which slowly moves from left to right)

and they float till a certain height untill they dissolve (fade to 0%).

I want to have 3 different kind of bubble MC’s which I want to generate (duplicate MC???) at random.

Further I don’t want them to clog eachothers, so they should not be able to move on top of eachothers.

For filesize reasons I want to do this as much as possible with an actionscript…

But how? Your suggestions and help are much appreciated :slight_smile:

download thoriphes bubles attachment here:
http://www.kirupaforum.com/forums/showthread.php?s=&threadid=24173&highlight=bubbles

it might help you

Everything was lookin easy until you said that bubbles can’t be on top of eachother. Now you’re looking at checking the location of all these bubbles and comparing each to the location of every other bubble.

This will make your bubbles sloooowwwww… it is, of course, entirely doable.

can’t that be done with a hittest?

really cool script btw :slight_smile:

have some questions though :slight_smile:

  • what should I do when I want them to go only till the border of the MC i will place them in (which is not the border of the actual main.SWF)

  • instead of simply disappearing, i would like em to fade to alpha 0%… how would I do that?

[script]
onClipEvent (load) {
a = 0;
i = 0;
// randomizes the x-motion and y-motion (for the y, how
// fast it moves up, for x, how far back and forth the
// bubble moves.
xMove = random(100)+1;
yMove = random(10)+1;
// size = random(100)/100;
if (_name == “bubbles”) {
_visible = false;
}
}
onClipEvent (enterFrame) {
// the script for all the movieclips except the main one.
if (_name != “bubbles”) {
// this makes the bubbles move back and forth and
// centers the motion.
_x = Math.sin(a)*xMove+400;
// this moves it up
_y -= yMove;
// this increments what goes into the Sine function
// above which makes the values go back and forth,
// which is what you see when the bubbles are moving.
// if you have a graphing calculator, graph y=sin(x)
// and you’ll see what i mean.
a += 0.1;
if (this._y<0) {
// once is goes offscreen, take it out
this.removeMovieClip();
}
} else {
// the script for the main clip
// (what you see on the stage)
++i;
// this makes the bubbles
duplicateMovieClip (this, “bub”+i, i);
// limiter, there can only be 75 bubbles on the screen
// at once (processor saver)
if (i == 75) {
// resets counter so the bubble in layer 0, if it’s
// still on the screen gets replaced, so disappears
i = 0;
}
// randomizes the size
size = random(100)/100;
_parent[“bub”+i]._width *= size;
_parent[“bub”+i]._height *= size;
}
}

[/script]

It can kinda be done with hitTest, but it’s the same idea there, you will have to hitTest each bubble against every other bubble.

To make it fade out - make the bubble an MC with the first frame a normal bubble, then the next 20 or so (whatever you want) frames are the tween out to 0 alpha. Then tell the MC that it should play() when it get’s to a certain _y.

hmmm, yes, but this would result in all bubbles fading out at the exact same height… while then I would prefer that it would fade out more randomly… if that is possible…

but code-wise, how would that be done… and wouldn’t that imply that the code would have to loop?

Sure it’s possible.

Just have some kind of random trigger, like

onEnterFrame = function(){
// other stuff you want, movement, etc.
random(10) == 0 ? bubble.play() : null;
}

Yes the code would have to loop, that’s what the ‘onEnterFrame’ function does for you.

If I didn’t have to go to class I would make an fla for you, sorry. Maybe later.

thanks :slight_smile:

but where should I put this code and could you more or less explain what this snippet of code does?