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.- Start of Frame
: Start loop "Create Rain" 800 times
: Play sample rain 0 times
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.
- On loop "Create Rain"
: Create
at (0,0) layer 2
: Set X position to X Left Frame-100+Random(420)
: Set Y position to Random(168)
At first,
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,

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

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