Step 2: Create the Rain

Using a fast loop, we can easily create 800 Raindrop objects in an instant. Fast looping is absolutely essential to programming in MMF2. If you are unfamiliar with fast loops, please read this article.
At the start of the frame, we start the "Create Rain" loop. We also play a sound effect called rain.
The rain sample is embedded within Falling Rain.mfa. Simply click Play and loop sample and the file will appear in the samples list. Note, playing a sample 0 times will continuously loop the sample.
When you refer to an object during the same event that created it, all actions will only effect that instance of the object. For example, if we create a Raindrop object and in the same event set the X and Y position, only this newly created Raindrop will be moved, leaving all the pre-existing Raindrop objects where they are.

At first, X Left Frame-100+Random(420) may seem a little confusing, so lets break it down...

The user can never see outside the frame window, so it makes sense to only create raindrops within the frame window. X Frame Left is an expression which returns the X co-ordinate at the left edge of the frame window.

Random() is an expression which returns a random number. For example, Random(10) will return a random number between 0 and 9. Our frame window is 320 pixels wide, so we could set the X position of each initial raindrop to X Left Frame+Random(320), but because our rain will fall at an angle, as time goes by, there would be a visible gap in the bottom left corner as shown below.


To avoid the gap, the random number range must begin before the left edge of the frame. In our case, 100 pixels will do the trick, and the expression becomes X Left Frame-100+Random(420), shown below.


You will notice that each Raindrop object is displaying one of two images. These are stored as single frames in different animation directions, left and right. If you check the object properties, you will see that the initial direction is set to both left and right. This means when the object is created, a random direction is selected.

If you test the application and run around the level, you will also notice that each Raindrop object will move with you. If this bothers you, it can be disabled by checking "Follow the frame" in the object properties. It is a matter of personal preference.
4