A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Effortless snow through actionscript?

Hybrid View

  1. #1
    Member
    Join Date
    Feb 2001
    Posts
    79

    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!

  2. #2
    Senior Member Computer Dork's Avatar
    Join Date
    Mar 2001
    Location
    St. Louis
    Posts
    1,026
    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.

  3. #3
    Member
    Join Date
    Feb 2001
    Posts
    79
    AMAZING!
    That's awsome. Thanks so much!

  4. #4
    Member
    Join Date
    Feb 2001
    Posts
    79
    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?

  5. #5
    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!

  6. #6
    Member
    Join Date
    Feb 2001
    Posts
    79
    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!

  7. #7
    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!

  8. #8
    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

  9. #9
    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.

  10. #10
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center