登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

强大才能生存

国防、国力、国人

 
 
 

日志

 
 

Flash AS制作下雪动画效果  

2009-01-06 10:14:30|  分类: AS2.0课堂 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

                     效果如下:

< P>

 

使用纯Flash Actionscript实现的下雪动画效果

function addMasker()

{

_root.createEmptyMovieClip("masker", -2);

with (masker)

{

lineStyle(1, 13421772, 100);

beginFill(0, 100);

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()

{

var _l1 = 0;

while (_l1 < snowNum)

{

var _l2 = snowSpace.createEmptyMovieClip("s" + _l1, _l1);

var _l3 = Math.random() * 3;

drawSnow(_l2, _l3);

_l1++;

} // end while

} // End of the function

function drawSnow(snow, radius)

{

var p = radius * 0.900000;

with (snow)

{

colors = [13421772, 16777215];

alphas = [100, 100];

ratios = [0, 255];

matrix = {matrixType: "box", x: -Math.random() * 2 * radius, y: -Math.random() * 2 * radius, w: 2 * radius, h: 2 * radius, r: 1.570796};

beginGradientFill("radial", colors, alphas, ratios, matrix);

curveTo(p, -p, radius, 0);

curveTo(p, p, 0, radius);

curveTo(-p, p, -radius, 0);

curveTo(-p, -p, 0, -radius);

endFill();

} // 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.141593 / 180);

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

var sceneWidth = 550;

var sceneHeight = 400;

var sideDisWidth = Stage.width / 2 - sceneWidth / 2;

var sideDisHeight = Stage.height / 2 - sceneHeight / 2;

var snowNum = 150;

var snowSpace = _root.createEmptyMovieClip("room", 1);

addMasker();

  评论这张
 
阅读(1226)| 评论(9)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018