Rain problem
- MichaelJ
-
MichaelJ
- Member since: Mar. 2, 2009
- Offline.
-
- Forum Stats
- Member
- Level 18
- Voice Actor
Hi, I have been messing around with this rain effect in flash, but I have encountered a problem. On the main menu of my flash, I have a rain movie clip with the identifier of "rain_id" on the stage, and I have the following code on the frame:
stop();
var rain_speed:Number = 20;
var rain_density:Number = 50;
for (i=0; i<=rain_density; i++) {
_root.attachMovie("rain_id", "rain"+i, _root.getNextHighestDepth(), {_x:Math.random()*Stage.width, _y:Math.random()*Stage.height});
}
makeRain = function () {
for (i=0; i<=rain_density; i++) {
_root["rain"+i]._y += rain_speed;
if (_root["rain"+i]._y>Stage.height) {
_root["rain"+i]._y = -2;
}
}
};
setInterval(makeRain, 20);
It works, and when I go to a different frame all I have to do to make the rain stop is remove the rain movie clip from the stage. The problem is, when I go back to the menu(in the swf), the rain seems to be frozen on the stage. There is a new layer of moving rain over it. How do I remove that 'frozen layer' of rain? I have tried putting setInterval(makeRain, 0); on the button that takes you away from the menu, but it will not work. (Basically, on the button that takes you away from the menu, what code should I put in it to make all of the rain be removed from the stage, so that when I go back to the menu, the rain will start again?)
- MichaelJ
-
MichaelJ
- Member since: Mar. 2, 2009
- Offline.
-
- Forum Stats
- Member
- Level 18
- Voice Actor
- 4urentertainment
-
4urentertainment
- Member since: Aug. 1, 2008
- Offline.
-
- Forum Stats
- Moderator
- Level 13
- Game Developer
I'm not sure if this will fix it, but the reason why removing the rain movie clip causes a problem is that you're not using that rain movie clip in the first place. You're attaching it from the library, try replacing the attachMovie line with:
_root.rain_id.duplicateMovieClip("rain"+i, _root.getNextHighestDepth(), {_x:Math.random()*Stage.width, _y:Math.random()*Stage.height});
}
Theoretically, it should work. I'm not sure though.
- MichaelJ
-
MichaelJ
- Member since: Mar. 2, 2009
- Offline.
-
- Forum Stats
- Member
- Level 18
- Voice Actor
I tried it but it does not work. I will send you the file later Omar, and explain the problem more thoroughly.



