Hi, I’m doing a flash movie and I would like to know if anybody knows how to simulate rain with Action Script in flash mx.
I tried modifying some snow effect I found in the site, but it didn’t work properly.
Thank You! =)
Hi, I’m doing a flash movie and I would like to know if anybody knows how to simulate rain with Action Script in flash mx.
I tried modifying some snow effect I found in the site, but it didn’t work properly.
Thank You! =)
I rememeber someone asking for the same effect here so you might want to do a search.
Also here is a file I got a long time ago. It’s not too pretty, but maybe it will give you some ideas.
[AS]var maxDrops = 50;
var maxSpeed = 20;
var minSpeed = 10;
var movieWidth = 300;
var movieHeight = 200;
this.createEmptyMovieClip(“drop”, -1);
drop.lineStyle(.25, 0x000000, 100);
drop.moveTo(0, 0) and drop.lineTo(5, -5);
drop._visible = false;
MovieClip.prototype.rainDown = function() {
this.speed = Math.random()(maxSpeed-minSpeed)+minSpeed;
this.onEnterFrame = function() {
this._x -= this.speed;
this._y += this.speed;
if (this._y>=movieHeight) {
this._x = Math.random()(movieWidth+200);
this._y = -5;
this.speed = Math.random()(maxSpeed-minSpeed)+minSpeed;
}
};
};
for (var i = 0; i<maxDrops; i++) {
mc = drop.duplicateMovieClip(“drop”+i, i);
mc._x = Math.random()(movieWidth+200);
mc.rainDown();
}[/AS]
Kinda ghetto, but I whipped it up real quick
looks mighty spiffy to me.
Thank you!!! It was really useful!!
Cool :thumb:
Heres a move clean cut version that hides the rain that isn’t on the viewable stage…
[AS]//define variables to use in the movie
var maxDrops = 50;
var maxSpeed = 20;
var minSpeed = 10;
var movieWidth = 300;
var movieHeight = 200;
//create mask the size of your stage
this.createEmptyMovieClip(“mask”, -1);
mask.beginFill(0xFF0000, 100);
mask.moveTo(0, 0);
mask.lineTo(movieWidth, 0);
mask.lineTo(movieWidth, movieHeight);
mask.lineTo(0, movieHeight);
//create container and drop clip inside
this.createEmptyMovieClip(“container”, -2);
container.createEmptyMovieClip(“drop”, -1);
container.drop.lineStyle(.25, 0x000000, 100);
container.drop.moveTo(0, 0) and container.drop.lineTo(5, -5);
container.drop._visible = false;
//set the mask clip to be a mask to the container clips
container.setMask(mask);
//function for motion
MovieClip.prototype.rainDown = function() {
this.speed = Math.random()(maxSpeed-minSpeed)+minSpeed;
this._alpha = Math.random()(100-10)+10;
this.onEnterFrame = function() {
this._x -= this.speed;
this._y += this.speed;
if (this._y>=movieHeight) {
this._x = Math.random()(movieWidth+200);
this._y = -5;
this._alpha = Math.random()(100-10)+10;
this.speed = Math.random()(maxSpeed-minSpeed)+minSpeed;
}
};
};
//create rain clips inside the container clip
for (var i = 0; i<maxDrops; i++) {
mc = container.drop.duplicateMovieClip(“drop”+i, i);
mc._x = Math.random()(movieWidth+200);
mc.rainDown();
}[/AS]
[edit]I added a little more depth by adding a random alpha property[/edit]
Slightly more vertical…
[AS]//define variables to use in the movie
var maxDrops = 50;
var maxSpeed = 20;
var minSpeed = 10;
var movieWidth = 300;
var movieHeight = 200;
//create mask the size of your stage
this.createEmptyMovieClip(“mask”, -1);
mask.beginFill(0xFF0000, 100);
mask.moveTo(0, 0);
mask.lineTo(movieWidth, 0);
mask.lineTo(movieWidth, movieHeight);
mask.lineTo(0, movieHeight);
//create container and drop clip inside
this.createEmptyMovieClip(“container”, -2);
container.createEmptyMovieClip(“drop”, -1);
container.drop.lineStyle(.25, 0x000000, 100);
container.drop.moveTo(0, 0) and container.drop.lineTo(2, -7);
container.drop._visible = false;
//set the mask clip to be a mask to the container clips
container.setMask(mask);
//function for motion
MovieClip.prototype.rainDown = function() {
this.speed = Math.random()(maxSpeed-minSpeed)+minSpeed;
this._alpha = Math.random()(100-10)+10;
this.onEnterFrame = function() {
this._x -= this.speed/2;
this._y += this.speed;
if (this._y>=movieHeight) {
this._x = Math.random()(movieWidth+200);
this._y = -5;
this._alpha = Math.random()(100-10)+10;
this.speed = Math.random()(maxSpeed-minSpeed)+minSpeed;
}
};
};
//create rain clips inside the container clip
for (var i = 0; i<maxDrops; i++) {
mc = container.drop.duplicateMovieClip(“drop”+i, i);
mc._x = Math.random()(movieWidth+200);
mc.rainDown();
}[/AS]
Can anyone tell I am bored?
That’s superb!! - not sure quite how bored you are, but, if you increased the number of drops and varied their alpha levels randomly, sped it up, and faded the impact circles out the further away they were, and made it all greyer… it’d look like London.
Actually if I did all that it would look like someones computer would blow up from the CPU Usage
Ok - so perhaps more like New York…:beam:
:: Copyright KIRUPA 2024 //--