To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flash MX

Reply
 
Thread Tools Search this Thread Display Modes
Old 11-15-2003, 11:16 PM   #1
inyquist
Member
 
Join Date: Feb 2001
Posts: 78
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!
inyquist is offline   Reply With Quote
Old 11-15-2003, 11:44 PM   #2
Computer Dork
Senior Member
 
Computer Dork's Avatar
 
Join Date: Mar 2001
Location: St. Louis
Posts: 1,018
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.
Computer Dork is offline   Reply With Quote
Old 11-15-2003, 11:53 PM   #3
inyquist
Member
 
Join Date: Feb 2001
Posts: 78
AMAZING!
That's awsome. Thanks so much!
inyquist is offline   Reply With Quote
Old 11-15-2003, 11:58 PM   #4
inyquist
Member
 
Join Date: Feb 2001
Posts: 78
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?
inyquist is offline   Reply With Quote
Old 11-16-2003, 12:11 AM   #5
oldnewbie
Banned
 
Join Date: Apr 2001
Location: Montréal, Québec.
Posts: 25,397
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!
oldnewbie is offline   Reply With Quote
Old 11-16-2003, 12:18 AM   #6
inyquist
Member
 
Join Date: Feb 2001
Posts: 78
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!
inyquist is offline   Reply With Quote
Old 11-16-2003, 12:26 AM   #7
oldnewbie
Banned
 
Join Date: Apr 2001
Location: Montréal, Québec.
Posts: 25,397
That wasn't my code, but the snow that fell really fell here!
oldnewbie is offline   Reply With Quote
Old 11-16-2003, 12:45 AM   #8
oldnewbie
Banned
 
Join Date: Apr 2001
Location: Montréal, Québec.
Posts: 25,397
In fact here's some accumulation on text...

http://www.flashkit.com/movies/Effec...2455/index.php

And quite a few snow files here...

http://www.flashkit.com/search.php?t...&submit=Submit
oldnewbie is offline   Reply With Quote
Old 11-30-2004, 10:25 AM   #9
DeVeau31
Member
 
Join Date: Nov 2000
Location: MA
Posts: 82
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.
DeVeau31 is offline   Reply With Quote
Old 11-30-2004, 01:45 PM   #10
NTD
Banned
 
NTD's Avatar
 
Join Date: Feb 2004
Posts: 3,438
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.
NTD is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Flash MX

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:37 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.