This is a simple scenario of raining in a cemetery. It reminds me the day I had my 20 years old birthday, I went to the biggest cemetery of my city just want to find a place to think about my life of the 20 years. Not like America, the cemeteries in China are usually located in suburb with large area. I have been to many large or small cemeteries. Some in the villege, it was quite simple, only put a small stone on the mound, and you may even not notice it. Some were on the hill, white tombstones cover the whole hill, it was so spectacular. I'd like to read the word on the tombs, which described their life. Cemetery is a quiet place for people to think. Think about life and death. Anyway, the code of raining in AS2 is below the demo. It is not a perfect raining code, you will find if you stay on this page for long time, the rain will become heavier :) .
The rainy is not completely controled by code, firstly, you should make a movie clip: draw a short line in grey vertically, make a tweened animation to let it drop a short distance(maybe 1/3 of the height of the stage about 10 frames, then make blank frames, on 25th frame, write code: stop(); in the actionscript window.Name this movie clip :"rain", copy about 8-10 this mc and put it on the stage anywhere.On the first frame of your animation, add the code below:
//code:
function rainy(){
r=random(200)+20;//choose a bigger number to make different "droplet" has different depth
duplicateMovieClip("rain",r,r);// duplicate MovieClip called "rain"
a=random(550);//You can also set 550-20 to make sure the rain will not out of the stage
b=random(400);//You can also set 400-10 to make sure the rain will not out of the stage
if(a<=550){
//if a (which is the _x of the droplet is still on the stage (my stage size is 550*400)
a=a+20;
}
if(b<=50){
b=b+10;
//Since b is the height when the rain start to drop, it should not be too low
}
setProperty(r, _x,a);
setProperty(r, _y,b);
//radom produce the rain droplets on the stage
updateAfterEvent();
//make the animation smoothly
r++;
if (r>220) {
clearInterval(raining);
//if the rain is too much, then reset the interval,the chance r=221 is not that big
}
}
raining=setInterval(rainy,120);
//execute this function every 0.12 seconds
The reason why the rain is become heavier is that my swf is only about 160 frames, every time it loops, the MC called "rain" will be duplicated again, the rain become more. There are many methods to control the number of droplet,like make a variable to record the times droplets are duplicated, and when it is more than a certain number, you could use clearInterval() function to reset it.
To View Flash Snowy Animation:
Flash animation : rainy & snowy (2)
The rainy is not completely controled by code, firstly, you should make a movie clip: draw a short line in grey vertically, make a tweened animation to let it drop a short distance(maybe 1/3 of the height of the stage about 10 frames, then make blank frames, on 25th frame, write code: stop(); in the actionscript window.Name this movie clip :"rain", copy about 8-10 this mc and put it on the stage anywhere.On the first frame of your animation, add the code below:
//code:
function rainy(){
r=random(200)+20;//choose a bigger number to make different "droplet" has different depth
duplicateMovieClip("rain",r,r);// duplicate MovieClip called "rain"
a=random(550);//You can also set 550-20 to make sure the rain will not out of the stage
b=random(400);//You can also set 400-10 to make sure the rain will not out of the stage
if(a<=550){
//if a (which is the _x of the droplet is still on the stage (my stage size is 550*400)
a=a+20;
}
if(b<=50){
b=b+10;
//Since b is the height when the rain start to drop, it should not be too low
}
setProperty(r, _x,a);
setProperty(r, _y,b);
//radom produce the rain droplets on the stage
updateAfterEvent();
//make the animation smoothly
r++;
if (r>220) {
clearInterval(raining);
//if the rain is too much, then reset the interval,the chance r=221 is not that big
}
}
raining=setInterval(rainy,120);
//execute this function every 0.12 seconds
The reason why the rain is become heavier is that my swf is only about 160 frames, every time it loops, the MC called "rain" will be duplicated again, the rain become more. There are many methods to control the number of droplet,like make a variable to record the times droplets are duplicated, and when it is more than a certain number, you could use clearInterval() function to reset it.
To View Flash Snowy Animation:
Flash animation : rainy & snowy (2)