FLASH CS6中如何使用代码制作下雪效果(AS2版)

2025-11-01 13:50:53

1、打开FLASH CS6软件,新建一个AS2文档,如下。

FLASH CS6中如何使用代码制作下雪效果(AS2版)

2、将舞台背景色设置为黑色,或画一个黑色的形状。

FLASH CS6中如何使用代码制作下雪效果(AS2版)

3、在舞台上画一个雪花,如下图,我只是画一个圆,同学们可以自行发挥。

FLASH CS6中如何使用代码制作下雪效果(AS2版)

4、选择雪花转换为影片剪辑,并设置Actionscript链接如下图。标识符设置成SNOW,其它默认即可。

FLASH CS6中如何使用代码制作下雪效果(AS2版)

FLASH CS6中如何使用代码制作下雪效果(AS2版)

5、然后将舞台上的雪花删除,在主时间轴加如下代码:

var snow_count:Number=100;//雪花数量

init();

function init()

{

for(var i=0;i<snow_count;i++)

{

this.attachMovie("SNOW","s"+i,this.getNextHighestDepth());

this["s"+i]._x=Stage.width*Math.random();//随机x坐标

this["s"+i]._y=Stage.height*Math.random();//随机y坐标

this["s"+i]._alpha=0.3+0.7*Math.random();//随机透明度

this["s"+i]._xscale=snowAry[i]._yscale=0.3+0.7*Math.random();//随机大小

this["s"+i].spd=2+2*Math.random();//随机下落速度

this["s"+i].onEnterFrame=function()

{

this._y+=this.spd;

if(this._y>Stage.height+this._height)//如果雪花到达舞台以外则重置

{

this._x=Stage.width*Math.random();//随机x坐标

this._y=-50;//固定y坐标

this._alpha=0.3+0.7*Math.random();//随机透明度

this._xscale=this._yscale=0.3+0.7*Math.random();//随机大小

this.spd=2+2*Math.random();//随机下落速度

}

}

}

}

6、代码没问题的话,现在ctrl+enter就可以看到下雪的效果了。

如果想停住下雪,则使用如下代码。

for(var i=0;i<snow_count;i++)

{

this["s"+i].onEnterFrame=null;

}

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢