|
-
Effortless snow through actionscript?
I'm trying to create an animation that has snowflakes falling in the background. I imaging that the flakes would gracefully move back and forth as it falls to the ground - much like a feather.
I know I could accomplish this by tweening keyframes, but I think it's time that I made things a bit easier on myself. There has to be a way to achieve this effect through actionscript and random numbers.
Does anybody out there know of a tutuorial that might help me to learn this type of actionscripting?
Thanks in advance!
-
Senior Member
0. New movie - fps 25, size 600x400.
1. Make a snowflake.
2. Put it into its own movieclip, put it on the stage with an instance name of "snow".
3. Make a new layer titled "actions". On the (only) frame, put these actions:
code:
for (n=0; n<50; n++) {
duplicateMovieClip(_root.snow, "snow"+n, n);
}
4. Put this on the snowflake clip:
code:
onClipEvent (load) {
movieWidth = 600;
movieHeight = 400;
i = 1+Math.random()*2;
n = -Math.PI+Math.random()*Math.PI;
this._xscale = this._yscale=50+Math.random()*100;
this._alpha = 75+Math.random()*100;
this._x = -10+Math.random()*movieWidth;
this._y = -10+Math.random()*movieHeight;
}
onClipEvent (enterFrame) {
rad += (n/180)*Math.PI;
this._x -= Math.cos(rad);
this._y += i;
if (this._y>=movieHeight) {
this._y = -5;
}
if ((this._x>=movieWidth) || (this._x<=0)) {
this._x = -10+Math.random()*movieWidth;
this._y = -5;
}
}
5. Kick back with a coffee and your mittens and chill.
-
AMAZING!
That's awsome. Thanks so much!
-
Hey, what would I have do to the code to make it so that they stop and accumulate at the bottom of the screen like real snowflakes do?
-
You would have to cheat it! And best way to cheat it is to imagine it's accumulating outside of view!
Seriously... I guess some kind of tweening or action scripted accumulation movie clip, but to be realistic it would have to be pretty slow... Unless this was a snow storm, like the one we just got here a few days ago!
-
Thanks again. And one last question for you...
In an effort to understand what you've done here I've been messing with the numbers in your code. Increasing the number of flakes on the screen, their size, speed, etc.
I thout it might be interesting to make them randomly rotate as they fell. So, I tried adding this line of code...
this._rotation = this._rotation=50+Math.random()*100;
Of course, it didn't work, which is pretty typical of the result I get when I try to do these things myself. Any idea why it's not working.
Sounds like it's pretty cold where you are. Stay warm!
-
That wasn't my code, but the snow that fell really fell here!
-
-
I like the effect that was just posted, the snow accumulating on the text, but I want to create an effect that piles up, not melts down. I checked out the script in that .fla and edited the melt graphic to a build up graphic and changed some numbers around but it's still not working. Any ideas? I got it to slow down the melt effect considerably, but can't get it to actually accumulate. Please help? Thanks in advance.
-
Banned
Hi,
To create a pile up effect, just make a ground variable that the snowflakes stop and and reduce that ground variable as the snow falls.....
code:
_root.onLoad = function() {
ground=400;
for (i=1; i<100; i++) {
duplicateMovieClip(mcSnowFlake, "snow"+i, i);
myFlake = _root["snow"+i];
myFlake._x = (Math.random(100)*550);
myFlake._y = (Math.random(100)*400);
myFlake.onEnterFrame = function() {
this._y += 5;
if (this._y>ground) {
delete this.onEnterframe;
ground--;
}
}
}
}
Hope it helps
NTD
Last edited by NTD; 11-30-2004 at 01:48 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|