Rain with Water Ripple Flash Effect Particle System

Step 4: Create Raining with Water Ripples Effect

The flash raining effect is almost finished. For many flash rain effect, this is the end of the tutorial. However we would like to add an interesting water ripples effect.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

A Flash raining effect without the water ripples effect is not perfect. This is the last step of this rain effect tutorial. We are going to add water ripples effect to rain drop particles when they fall into the sea or water. We also animate the cloud to make the movie looks more interesting.

The finished Flash Movie of this tutorial is shown as above.

Flash ActionScript Codes:

// Declare number of Rain Drops
var numOfRain:uint = 10;

// Create an Array to hold the Rain drops
var rainArray:Array = new Array();

// Create an Array to hold the Rain Ripple
var rippleArray:Array = new Array();

// Creates 10 Rain Drops on the stage.
for (var i:uint = 0; i < numOfRain; i++) {

// Create a new Rain Drop
// Remember to set linkage in Movie Library
var rain:RainDrop = new RainDrop();

// Add the Rain Drop to the stage

// Assign start location of Rain Drops
// x-axis: 0 - 490
// y-axis: 0 - 200
rain.x = Math.random() * 490;
rain.y = Math.random() * 200;;

// Assign random alpha to Rain Drop
// Math.random returns value between 0 - 1
// i.e.
// Minimum value = 0.4 + 0 = 0.4
// Maximum value = 0.4 + 0.6 = 1.0
// Summary:
// Assign random alpha between 0.4 and 1.0
rain.alpha = 0.4 + Math.random() * 0.6;

// Assign random scale to Rain Drop
// Math.random returns value between 0 - 1
// i.e.
// Minimum value = 0.3 + 0 = 0.3
// Maximum value = 0.3 + 0.3 = 0.6
// Summary:
// Assign random scale between 0.3 and 0.6
rain.scaleX = 0.3 + Math.random() * 0.3;
rain.scaleY = rain.scaleX;

// Assign random velocity (y-axis) to the Rain drop
// Math.random returns value between 0 - 1
// i.e.
// Minimum value = 6 + 0 = 6
// Maximum value = 6 + 5 = 11
// Summary:
// Math.random returns value between 2 - 5
rain.yVelocity = 6 + Math.random() * 5;

// Also assign a velocity in x-axis
// so that the rain will be dropped down with an angle
rain.xVelocity = 2;

// Put Rain Drop into rainArray Array to be used later for animation
rainArray.push(rain);

///////////////////////////////////
////////// Rain Ripple //////////
///////////////////////////////////

// Create a new Rain Ripple
// Remember to set linkage in Movie Library
var ripple:Ripple = new Ripple();

// Add the Rain Ripple to the stage

// Set to negative so that they cannot be seen when first add to stage.
ripple.y = -20;

// Scale the Ripple according to the size of Rain Drops
// so that:
// A bigger Rain Drop will have a bigger Ripple
// A smaller Rain Drop will have a smaller Ripple
ripple.scaleX = rain.scaleX;
ripple.scaleY = rain.scaleX;

// Put Rain Ripple into rippleArray Array to be used later for animation
rippleArray.push(ripple);

}

// Add ENTER_FRAME Event to animate the Rain Drops

function raining(evt:Event):void {

// Animate the Rain Drops one by one that hold in the Array
for (var i = 0; i < rainArray.length; i++) {
var rainParticles = rainArray[i];

var rippleParticles = rippleArray[i];

// Rain Drops falling down the y-axis
rainParticles.y += rainParticles.yVelocity;
rainParticles.x += rainParticles.xVelocity;

// If the Rain Drops fall near stage's height (stage.stageHeight)
if (rainParticles.y > 280 + Math.random() * 230) {

// Play the corresponding Ripple
rippleParticles.x = rainParticles.x;
rippleParticles.y = rainParticles.y;
rippleParticles.play();

// Locate the Rain Drop back to the Cloud (x-axis)
rainParticles.x = Math.random() * 490;

// Locate the Rain Drop back (y-axis)
// 10 pixel above the upper stage
rainParticles.y = -10;

}
}

}

/////////////////////////////////////////////////////////
////////// Moving Cloud Animation //////////
////////////////////////////////////////////////////////

function moveCloud(evt:Event):void {

//Use ENTER_FRAME event to fire action for every frame.

// Keep track the location of the Cloud
// If location small than the Stage Width, move to right by 1 pixel
// otherwise move back to the left of Stage by 110 pixel
if (cloud_mc.x < 620) {

cloud_mc.x += 0.25;} else {
cloud_mc.x = -110;}

}

// Call the moveCloud function when movie starts.
// Therefore the Cloud will start moving when movie starts.
moveCloud(null);