flash 代码 雪花飘落

本文介绍了一种使用Flash创建动态雪花效果的方法,通过调整雪花数量、速度等参数来模拟真实世界中雪花飘落的情景,并实现了雪花落在指定物体上后逐渐消失的效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


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++;
 }
};

转载于:https://www.cnblogs.com/JamyWong/archive/2010/05/31/1747908.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值