Professional Documents
Culture Documents
Creating RAIN EFFECT With ACTIONSCRIPT
Creating RAIN EFFECT With ACTIONSCRIPT
The main function, with some parameters making the effect easy to adapt to your
needs. You can change the number of drops, the speed at which the drops fall,
the speed at which the drops will move horizontally, the size of the effect area
and the direction of the rain (left or right).
Step 12 - Position
Set an initial random position for the Drops.
1 drop.x = Math.random() * (hArea + offset);
2
3 drop.y=Math.random()*vArea;
Step 13 - Scale
1 drop.scaleX = Math.round(((Math.random() * 0.8) + 0.3) * 10) / 10;
2 drop.scaleY=drop.scaleX;
This sets the scale of the Drops between 0.3 and the original size.
Step 15 - Direction
01 private function inTheDirection():void
02 {
03 for (var i:int = 0; i < dropsNumber; i++)
04 {
05 switch (dropsVector[i].dir)
06 {
07 case "left" :
08
09 dropsVector[i].addEventListener(Event.ENTER_FRAME, moveLeft);
10
11 break;
12
13 case "right" :
14
15 dropsVector[i].scaleX*=-1; //Our Drop was created going to the left, so we flip it to make it look like it's going to the right
16 dropsVector[i].addEventListener(Event.ENTER_FRAME, moveRight);
17
18 break;
19
20 default :
21
22 trace("Error");
23 }
24 }
25 }
In this function we use another "For" to get access to the MovieClips inside the
Vector. Then we check the direction parameter and add a Listener to the
corresponding function. This will all take care of the movement and the position.
Advertisement
This will create a new Rain Object, then call the main function to start the effect.
Finally we add the effect to the stage.
Conclusion
Remember that you can play with the parameters to get various effects and that
you can also change the drops by drawing whatever you like. Keep trying different
combinations to get the exact effect that you want.
I hope you enjoyed reading the tut as much as I did writing it. Thanks for reading!