flash雪花飘落案例介绍
最近很多地方都下起了鹅毛般的大雪,雪花一片一片飘落,一个晚上的时间就能给我们一个银装素裹的世界。记忆中,小时候过新年总是会有雪花的陪伴。说起下雪,就想起之前有做过雪花飘落的动画,重新拿来简单介绍一下:
1、新建flash文档,设置好尺寸宽度和高度。
2、绘制小雪花
Ctrl+F8 新建图形元件 shape 1,使用铅笔工具绘制,仔细观察过雪花的同学会发现其实雪花的结果还是挺复杂的,我这里就简单绘制了轮廓,如图
这是我已经绘制好的,首先用铅笔工具绘制一条直线,然后两边添加枝丫如下图
然后复制分别旋转一下,就能做成上图的雪花。
雪花绘制好以后,要等比例缩小到适合大小。
3、Ctrl+F8 新建影片剪辑2,把刚做好的shape 1雪花拖进影片剪辑2里。
并在库中添加 AS链接为:show1,以便后面调用。
4、Ctrl+F8 新建影片剪辑3,在图片第一帧中添加脚本如下:
function addMasker()
{
this.createEmptyMovieClip("masker", -2);
with (masker)
{
lineStyle(0, 13421772, 0);
beginFill(0, 0);
moveTo(sideDisWidth, sideDisHeight);
lineTo(sideDisWidth + sceneWidth, sideDisHeight);
lineTo(sideDisWidth + sceneWidth, sideDisHeight + sceneHeight);
lineTo(sideDisWidth, sideDisHeight + sceneHeight);
endFill();
} // End of with
createSnow();
} // End of the function
function createSnow()
{
for (var _loc1 = 0; _loc1 < snowNum; ++_loc1)
{
var _loc2 = snowSpace.createEmptyMovieClip("s" + _loc1, _loc1);
var _loc3 = Math.random() * 3;
drawSnow(_loc2, _loc3);
} // end of for
} // End of the function
function drawSnow(snow, radius)
{
var p = radius * 1.500000E+000;
with (snow)
{
attachMovie("show1", "sdfsdf", this.getNextHighestDepth());
} // End of with
snowProperty(snow, sceneWidth, sceneHeight);
} // End of the function
function snowProperty(snow, w, h)
{
snow._x = sideDisWidth + Math.random() * w;
snow._y = sideDisHeight + Math.random() * h;
snow._rotation = Math.random() * 120 + 30;
snow.stepX = Math.cos(snow._rotation * 3.141593E+000 / 360);
snow.stepY = Math.random() * 2 + 1;
setInterval(snowFall, 30, snow);
} // End of the function
function snowFall(snow)
{
snow._x = snow._x + snow.stepX;
snow._y = snow._y + snow.stepY;
if (sideDisWidth > snow._x)
{
snow._x = sideDisWidth + sceneWidth;
} // end if
if (sideDisWidth + sceneWidth < snow._x)
{
snow._x = sideDisWidth;
} // end if
if (sideDisHeight + sceneHeight < snow._y)
{
snow._y = sideDisHeight;
} // end if
} // End of the function
this.onResize = function ()
{
this.txtDimentions._x = Stage.width / 2 - this.txtDimentions._width / 2;
this.txtDimentions._y = Stage.height / 2 - this.txtDimentions._height / 2;
this.txtDimentions.text = Stage.width + "x" + Stage.height;
};
Stage.scaleMode = "exactFit";
Stage.align = "TL";
Stage.showMenu = false;
Stage.addListener(this);
this.onResize();
var sceneWidth = 800;
var sceneHeight = 600;
var sideDisWidth = Stage.width / 2 - sceneWidth / 2;
var sideDisHeight = Stage.height / 2 - sceneHeight / 2;
var snowNum = 180;
var snowSpace = _parent.createEmptyMovieClip("room", 1);
addMasker();
这样简单的雪花飘落就做好了,如果需要可以添加一张背景图,效果图如下:
用户登录
还没有账号?
立即注册