PDA

View Full Version : Snow Falling Without Dissappearing



tomyknoker
12-04-2006, 01:30 AM
Hi Guys,

With the attached file I've got some snow falling, I want the snow to build up st the bottom of the file like it would in real life... If anyone has any ideas would be great! Also here is the code if that helps...
snowNumber = 70;
var flakes:Array = new Array("snow", "flake2", "flake3","flake4")
for (i=0; i<snowNumber; i++) {
newSnow = _root[flakes[random(flakes.length)]].duplicateMovieClip("snow"+i, i);
newSnow._x = Math.random()*Stage.width;
newSnow._y = -Math.random()*300;
newSnow.maxSnowSpeed = Math.random()*4;
newSnow.wind = Math.random()*6;
newSnow._xscale = newSnow._yscale = newSnow.alpha = Math.random()*60+40
newSnow.onEnterFrame = function() {
this._rotation -= this.maxSnowSpeed+1;
if(this._y>Stage.height || this._x>Stage.width || this._x<0){
this._y = -Math.random()*300;
this._x = Math.random()*Stage.width;
} else {
this._y += this.maxSnowSpeed+1;
this._x += this.wind-4;
}

this._alpha = this.alpha;
};
}

djr33
12-04-2006, 09:03 AM
Since javascript isn't my area, I'll just offer some logic advice:

You could try to make it stop when it hits the bottom of the page.

However, that'll just make a line of snowflakes. Making it actually build on top of itself is VERY complex, since you would need to track each and every snowflake as it hits the bottom.... the code isn't setup for that now... and it would be a lot more to add, and might just not work due to memory overload in the browser, though I'm not sure about that.

I guess the other option is to randomize it... 1 in 10 stops 1/2" from the bottom of the page, etc. That wouldn't be perfect, but might be a little better, though.

BLiZZaRD
12-04-2006, 08:47 PM
Check out This Movie (http://www.flashkit.com/movies/Effects/Special_Effects/Snowing-Shawn_H-6928/index.php) to get the accumulation effect.

djr33
12-04-2006, 11:54 PM
Oh, oops. I thought the above was javascript, since the AS and JS look so similar. I think I thought it was the script from DD... nevermind.

Interesting example.

I can't tell from your code how large the image representing a snowflake is, but the problem may be that the example uses 1 px flakes which can easily fit together... with oddly shaped flakes, you'd get odd buildup. Either on touch, they'd stop at oddly "balanced" angles to each other, or you'd need to add in some sort of realistic bouncing/rotating on contact. Seems fairly complex.
Maybe setting it to stop when it hits the center of another flake... when the outside edge of a flake touches the center of another, it should stop... that would look more realistic and get a nice layered effect.

BLiZZaRD
12-05-2006, 12:25 AM
Using hittest is a good option, but again a lot of coding.

To prevent the oddly shaped build up, he could always leave the code the way it is and make a masked layer with the "buildup" and remove the mask over time.

Plenty of ideas, depends on the execution.

tomyknoker
12-06-2006, 02:02 AM
Using hittest is a good option, but again a lot of coding.

To prevent the oddly shaped build up, he could always leave the code the way it is and make a masked layer with the "buildup" and remove the mask over time.

Plenty of ideas, depends on the execution.Hey Blizzard! Hey do you have any idea how I can make the snow on a particular layer... I moved it to the bottom of all the layers but when it falls it still falls on top of all the elements, maybe it's to do with _root?

BLiZZaRD
12-06-2006, 10:42 AM
Not sure what you mean.. shouldn't the snow be on the top of everything else?

Anyway, you can set the nextHighestDepth stuff, or keep it on the same depth etc etc... when you make the snow (flake1, flake2, etc) each is being placed on a layer on top of the previous, over time they are going to be in the thousands, and regardless of layer placement in the FLA the swf will continue to build.

Why I suggested the mask option. With that you can only have say 100 random flakes, and REMOVE each flake as it's _y>=600 or so. Then it will not build up on the depth layers and you still produce the effect that it is "building" a nice little pile.