Sunday, January 4, 2009

Snow or rain in flash(Wk11_1)

During complete my flash assignment on typeface I found that the flash will become more interesting if it contains rain or snow or anything falling down randomly.In order to make this effect, we create a an object with shapes of small circle(for snow) or sharp oval(for rain) in a new layer at the first frame and convert it into a movie clip. In this tutorial I will introduce the way to make a falling snow. After converting to a movie clip, we name it as "snow" in instance of this movie clip. Next, we add this action script code for the movie clip :


onClipEvent (load) {
movieWidth = 350;
movieHeight = 263;

i = 1+Math.random()*2;
k = -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 += (k/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;
}
}

We must also look at the movieWidth and movieHeight, we must adjust these based on our size of the flash.

after all, we add this code for the first frame in the timeline:

for (k=0; k<50; k++) {
duplicateMovieClip(this.snow, "snow"+k, k);
}

Now, let's check what will happen :) .

Source(Vietnamese): http://www.ngovancong.com/?nvc=act:news|newsid:980

No comments: