Bubbles - duplicate problems
Hi!
I'm working on a application with some bubbles. Each bubble goes from the bottom to the top. It works just fine with just one bubble, but when I duplicate the bubble it just stops on it's way towards the top. I want to have many of them, with different properties.
Could there be a "level" problem or?
Here's the code:
Code:
function createBubble(){
i++;
scale = random(120) + 30;
xMove = random(10)+1;
yMove = random(30)+1;
bubble = bubble_mc.duplicateMovieClip("bub" + i, i);
bubble._xscale = scale;
bubble._yscale = scale;
}
my_btn.onPress = function(){
//myBubble = setInterval(createBubble, random(3000) + 100);
createBubble();
}
this.onEnterFrame = function() {
bubble._y -= yMove;
bubble._x = Math.sin(a) * xMove + 150;
a += 0.2;
if(bubble._xscale > 0){
bubble._xscale -= scaleFactor;
bubble._yscale -= scaleFactor;
}
if(bubble._y < 0){
removeMovieClip(bubble);
createBubble();
}
}
Thankful for some advice
/S-fish
Or maybe try something like this...
Code:
stop();
var i = 0;
var a = 0.15;
var scaleFactor = 0.5;
var intID = "";
bubble_mc._visible = 0;
var stopped = true;
//
function getRand(maxNum, minNum) {
return Math.floor(Math.random() * (maxNum - minNum)) + minNum;
}
function createBubble() {
clearInterval(intID)
if (!stopped){
intID = setInterval(createBubble, getRand(2000, 100))
}
i++;
bubble = bubble_mc.duplicateMovieClip("bub" + i, i);
bubble.scale = getRand(120, 30);
bubble._xscale = scale;
bubble._yscale = scale;
bubble.xMove = getRand(10, 1);
bubble.yMove = getRand(30, 1);
bubble.a = a;
bubble.onEnterFrame = function() {
this._y -= this.yMove;
this._x = Math.sin(this.a) * this.xMove + 150;
this.a += 0.2;
if (this._xscale > 0) {
this._xscale -= scaleFactor;
this._yscale -= scaleFactor;
}
if (this._y < 0) {
this.removeMovieClip();
delete this.onEnterFrame;
}
};
}
my_btn.onPress = function() {
stopped = !stopped;
if (!stopped){
createBubble();
trace("bubbles on")
}else{
trace("bubbles off")
}
};