I would like to replicate the falling snow technique ( http://www.kirupa.com/developer/flash8/snow.htm ) on 2 layers.
This is so I can have foreground snow in front of a character and background snow behind him.
Any ideas on the best way to go about this? I tried duplicating a copy of the script onto a second layer but it only shows one set of snow. Even when I change all the variable names and make a new snowflake.
My developer skills are very minimal so I don’t know why it’s not working - I suspect there’s a more efficient way anyway?
When I duplicated the code I appended a “2” to the second copy of everything (all the variable names etc, including the function name). So it’s trying to call init and init2 both at once. Could this be the problem? Or because it’s trying to perform two “onEnterFrame” at the same time?
I made one snowflake white and the other red so I could see what’s happening. If I remove one script, the other works and vice versa. This leads me to believe that in my programming ignorance I’m breaking some basic law. When trying to run, it times out and crashes. I’m definately confusing it somehow.
Yeah I know that’s dodgy. I was just trying to get it working in any way I could before refining. But I didn’t even get that far…
The code is on this page (there’s only one script so it’s easy to see what it does in one place): http://www.kirupa.com/developer/flash8/snow.htm
Mine is exactly the same except I’ve duplicated the script. Which is incorrect of course, so what would be the best way to go about achieving what I want? I really would need to be able to set the parametres individually for both sets of snow (so the one’s in background layer are smaller and slower to create a better sense of depth in the scene).
Is using this script the most efficient way to animate snow? It seems to run poorly pretty quicky. If I add more than 50 snowflakes it slows down pretty badly. My stage is 800 x 500 px. Are there any better snow scripts out there or is this as good as it’ll get?
i think it looks fairly efficient.
You can put into seperate clips just adapting the original script slightly
width = 300;
height = 200;
max_snowsize = 10;
snowflakes = 50;
//depth,linkage id,and vertical velocity
function makesnow(d, s, vely) {
var c = this.createEmptyMovieClip("t", d);
for (i=0; i<snowflakes; i++) {
var t = c.attachMovie(s, "snow"+i, i);
t._alpha = 20+Math.random()*60;
t._x = -(width/2)+Math.random()*(1.5*width);
t._y = -(height/2)+Math.random()*(1.5*height);
t._xscale = t._yscale=50+Math.random()*(max_snowsize*10);
t.k = 1+Math.random()*vely;
t.wind = -1.5+Math.random()*(1.4*3);
t.onEnterFrame = mover;
}
}
mover = function () {
this._y += this.k;
this._x += this.wind;
if (this._y>height+10) {
this._y = -20;
}
if (this._x>width+20) {
this._x = -(width/2)+Math.random()*(1.5*width);
this._y = -20;
} else if (this._x<-20) {
this._x = -(width/2)+Math.random()*(1.5*width);
this._y = -20;
}
};
//mc is the instance name of the character thingy on the stage -made into a movieclip
mc.swapDepths(15);
makesnow(10, "snow", 2);
//you need another instance of snow in the library which you can color,resize etc
//linkage identifier snow2
makesnow(20, "snow2", 5);
Thanks heaps Scallywag, that’s working pretty well. It would be good to control the amount of snow separately for each of the two groups but I guess this isn’t critical.
The main problem with the original script (and same with modded version) is that when you add wind it means a lower corner of the stage won’t get any snow across it because it floats down from the top then across -leaving a triangle shape of uncovered stage on the opposite side to the wind direction. I made the width wider than the stage which helps a little, but I’m guessing this is adding uneccessary processing weight? (My stage is 800 wide so I set the snow width to 900 -tends to cover up the hole a little bit but not perfect.)
[quote=Gombul;2350758]Thanks heaps Scallywag, that’s working pretty well. It would be good to control the amount of snow separately for each of the two groups but I guess this isn’t critical.
The main problem with the original script (and same with modded version) is that when you add wind it means a lower corner of the stage won’t get any snow across it because it floats down from the top then across -leaving a triangle shape of uncovered stage on the opposite side to the wind direction. I made the width wider than the stage which helps a little, but I’m guessing this is adding uneccessary processing weight? (My stage is 800 wide so I set the snow width to 900 -tends to cover up the hole a little bit but not perfect.)[/quote]
you could just add another param to the function and remove the snowflakes variable
[quote=Gombul;2351190]Cool, snowflakes parametre doing the trick.
Still not sure about the triangle issue though. Need some to fall from the sides too maybe?[/quote]
yes you could try that - maybe reduce wind as well so more fall vertically.Heres one variation but i think you just need to play about until you get the effect you want