flash 代码 雪花飘落
var frameTime = 4;
var sceneWidth = 400; //屏幕宽度
var sceneHeight = 400; //屏幕高度
var removeSnow = 100; //雪花数量
var speed = 40; //雪花速度
var distance = -0.3;
this.onEnterFrame = function () {
if (random (frameTime) == 0) {
mc = this.snow.duplicateMovieClip ("snow"+i, i+100); //snow为雪花。
mc._x = random (sceneWidth);
mc._xscale = mc._yscale=random (50)+50;
mc._alpha = mc._xscale;
mc._y = 0;
mc.s = random (100);
mc.onEnterFrame = function () {
this._y += this._xscale/speed;
this._x += random (2)-0.5+distance;
if (targetMc.hitTest (this._x, this._y, true)) { //targetMc为物体,雪花会放置与该物体上,然后溶化,消失。
mc = _root.snow.duplicateMovieClip ("dusnow"+j, j);
mc._x = this._x;
mc._y = this._y;
mc._alpha = this._alpha;
mc._xscale = mc._yscale=this._xscale;
mc.onEnterFrame = function () {
if (this.t++>removeSnow) {
this._alpha -= 5;
if (this._alpha<0) {
this.removeMovieClip ();
}
}
};
j++;
this.removeMovieClip ();
}
if (this._x<0 || this._x>sceneWidth || this._y>sceneHeight) {
this.removeMovieClip ();
}
};
i++;
}
};
var frameTime = 10;
var sceneWidth = 400;
var sceneHeight = 400;
var speed = 40;
var vibration = 20;
this.onEnterFrame = function () {
if (random (frameTime) == 0) {
mc = this.snowMc.duplicateMovieClip ("snowMc"+i, i+100);
mc._x = random (sceneWidth);
mc._xscale = mc._yscale=random (50)+50;
mc._alpha = mc._xscale;
mc._y = 0;
mc.s = random (100);
mc.onEnterFrame = function () {
this._y += this._xscale/speed;
this._x += Math.sin (this.s++/vibration);
if (this._y>sceneHeight) {
this.removeMovieClip ();
}
};
i++;
}
};