• Home
  • Free Tutorials
  • Free Video Tutorials

Adobe Photoshop
Autodesk 3ds Max
CSS
Flash
Help Center Live
iPhone
Joomla
Make Money Online!
Mambo
mIRC
Outlook Express
SEO / SEM
Simple Machine Forum
Target Explorer

Accumulative Snow Effect

Category : Flash Views : 31531
Version : 8 Rating : 
3.3/5 (53 votes)
  • Currently 3.30/5
  • 1
  • 2
  • 3
  • 4
  • 5
Type : Text Source File: accumulative-snow-effect.zip
Result: See the result


Previous | 1 | 2 | 3 | 4 | Next

//this point is where we have the snow //coordinates, so we will use this to make //hitTests later. var hitPoint = new Point(hitBitmap.rectangle.x, hitBitmap.rectangle.y); //the direction for the snow; 1 = right, -1 = left and 0 = none. var dir = Math.round(Math.random() * 2) - 1; //used to create new Movie Clips i = 0 //call the function setInterval every 50 milliseconds. setInterval(dropSnow, 50); function dropSnow () { //increase by 1 i++; //attach new snow _root.attachMovie("snow", "snow" + i, i); }

So now we have two bitmaps: visibleBitmap and hitBitmap.
visibleBitmap doesn稚 include the limits we draw earlier just the accumulated snow.
hitBitmap includes both snow and limits and we will use it just to make hitTests.

We are going to use them on the Snow Movie Clip, so open the actions for the first frame of the snow and paste:
//libraries for objects import flash.display.BitmapData; import flash.geom.Matrix; //random positions this._x = Math.random() * 400; this._y = Math.random() * 10 - 10; //random speed to fall var speed = Math.random() * 5 + 2 //random speed between 0 and 2; if "dir" is //negative the speed will be negative too and //the snow will go to the left, if its positive //the snow will go to the right and if its equal //to 0 the snow won稚 move on the _x coordinate. var Xspeed = (Math.random() * 2) * _root.dir this.onEnterFrame = function() { //new point set to this Movie Clip痴 coordinates var myPoint = new Object(); myPoint.x = this._x; myPoint.y = this._y; //if the "hitBitmap" hits with "myPoint" on the coordinates //of "_root.hitPoint" if (_root.hitBitmap.hitTest(_root.hitPoint, 0, myPoint)) { //new matrix use to draw the snow in the update hitBitmap //and visibleBitmap var drawMatrix:Matrix = new Matrix (); //this set the drawing location to our coordinates, so when we //draw this on the bitmaps it will draw on our current location drawMatrix.translate(this._x, this._y); //draw this Movie Clip on the bitmaps using the location we set //on the matrix object _root.hitBitmap.draw(this, drawMatrix); _root.visibleBitmap.draw (this, drawMatrix); //remove the Movie Clip this.removeMovieClip(); } //Move the Movie Clip down if we didn稚 hit anything this._y += speed; //move the Movie Clip left or right; if Xspeed is 0 the //Movie Clip wont move right or left. this._x += Xspeed; //if the Movie Clip didn稚 hit anything and left the screen if (this._y > 500) { //remove Movie Clip this.removeMovieClip(); } }

Test it now. I hope you liked this simple effect.


More cool tech articles from other blogs.

Place your ad here
Loading...


Previous | 1 | 2 | 3 | 4 | Next
How to Video Tutorials on software by Helpvids.com

Sponsors





All about design & printing
Studio | Advertisement | About Webzo | Contact Webzo | Terms of Use | Free Video Tutorials by Helpivds

Copyright © 2007 NR Concepts Ltd. All rights reserved.