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
Last edited by swordfish123; 02-08-2007 at 02:28 PM .
Attached Files
I think I got it mostly....here take a look....unfortunately i gotta run but here is the code.
Code:
stop();
i = 0;
a = 0.15;
scaleFactor = 0.5;
bubble_mc._visible = 0;
function createBubble(){
i++;
scale = random(120) + 30;
xMove = random(10)+i;
yMove = random(30)+i;
duplicateMovieClip("bubble_mc", "bub" + i, i);
trace(this["bub" + i]._name);
this["bub" + i]._y = 450;
this["bub" + i]._xscale = scale;
this["bub" + i]._yscale = scale;
this["bub" + i].onEnterFrame = function() {
this._y -= yMove;
this._x = Math.sin(a) * xMove + 150;
a += 0.2;
if(this._xscale > 0){
this._xscale -= scaleFactor;
this._yscale -= scaleFactor;
}
if(this._y < 0){
this.swapDepths();
removeMovieClip(this);
//createBubble();
}
}
}
my_btn.onPress = function(){
//myBubble = setInterval(createBubble, random(3000) + 100);
createBubble();
}
Thanx, but not exactly what I looking after...if you hit the button 10 times fast, we got a quite strange movement
You can check the attachment (only got the .swf-file), but this is the movemet I want. Many bubbles at the same time, and each of them with it's own property..
Attached Files
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")
}
};
Last edited by dawsonk; 08-22-2007 at 10:51 AM .
Thank you dawsonk, thats what I want...nice solution as well!
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width