学院首页 软件应用 编程开发 创意设计 认证培训 软件论坛
Flash Fireworks Dreamweaver Photoshop CorelDraw Illustrator FreeHand 3DsMAX AutoCAD

您的位置:学院 >> 创意设计 >> Flash >> Flash AS动画实例:风吹云飘草动


Flash AS动画实例:风吹云飘草动


  我们可以直接用Flash的ASAS代码生成风吹云飘,风吹着青草左右摇摆的动画。因为AS的运算会拖慢机器,所以这里就不提供效果演示了,给大家截个图。

Flash AS 实现好看的清晰的飘动云和风吹草动画

  制作方法如下。

  首先建立两个空的影片剪辑cloud和grass。

  先建立云的影片剪辑(里面什么都不画)

Flash AS 实现好看清晰的飘动云和风吹草动画

  选择该元件的第一帧,添加如下代码。

//Number of clouds
clouds=6;
//These are just general boundaries.
//To use exact boundaries, create a mask in the parent level of the size desired
//Height of the sky
skyheight=Stage.height;
//Width of the sky
skywidth=Stage.width;
//Max size of a cloud
cloudsize=300;
//Amount of blur applied to the shapes to make them cloud-like
blursize=40;
//Clouds move at a random speed. this is the minimum speed
cloudminspeed=.5;
//Variance in speed from cloud to cloud
cloudspeedvariance=1;
//Create the clouds
for(c=1;c<=clouds;c++){
//create an empty movie clip to hold the cloud
 this.createEmptyMovieClip("cloud"+c,this.getNextHighestDepth());
//generate a cloud. Pass in the instance name of the newly created cloud
 shapecloud("cloud"+c);
//Set the x position to a random position within the boundaries
 eval("cloud"+c)._x=Math.random()*skywidth-eval("cloud"+c)._x/2;
//Set the y position to a random position within the boundaries
 eval("cloud"+c)._y=Math.random()*(skyheight)-eval("cloud"+c)._height;
}
//Run at the start of each frame
onEnterFrame=function(){
//Run for each cloud
 for(c=1;c<=clouds;c++){
//Move the cloud to the left according to its speed
  eval("cloud"+c)._x-=eval("cloud"+c).cloudspeed;
//If the cloud is past the stage to the left, reset it to the right. Create a new shape and color  
  if(eval("cloud"+c)._x+(eval("cloud"+c)._width/2)+cloudsize<0){
//Reset the x position
   eval("cloud"+c)._x=skywidth;
//Reshape and recolor the cloud
   shapecloud("cloud"+c);
  }
 }
}
//This function creates the shape and color of a cloud
function shapecloud(cloudid){
//Clear the current contents of the cloud
 eval(cloudid).clear();
//Set the new shade between 224 and 255. This number is used for the red, green, and blue, to create a grayscale color
 cloudcolor=Math.round(Math.random()*31)+224;
//Use no line
 eval(cloudid).lineStyle(undefined, (cloudcolor+cloudcolor*0x100+cloudcolor*0x10000), 100, false, "none", "none", "none", 1);
//Set the fill color. cloudcolor is used 3 times, for red, green, and blue
 eval(cloudid).beginFill((cloudcolor+cloudcolor*0x100+cloudcolor*0x10000));
//Set a starting coordinate for the cloud 
 eval(cloudid).moveTo(Math.random()*cloudsize,Math.random()*cloudsize);
//Draw an invisible line to another point the combined lines form shapes, which are the clouds.
//They don't look much like clouds until the blur is applied
 eval(cloudid).lineTo(Math.random()*cloudsize,Math.random()*cloudsize);
 eval(cloudid).lineTo(Math.random()*cloudsize,Math.random()*cloudsize);
 eval(cloudid).lineTo(Math.random()*cloudsize,Math.random()*cloudsize);
 eval(cloudid).lineTo(Math.random()*cloudsize,Math.random()*cloudsize);
 eval(cloudid).lineTo(Math.random()*cloudsize,Math.random()*cloudsize);
//Apply a blur to the shape
 eval(cloudid).filters = [new flash.filters.BlurFilter(blursize,blursize,2)];
//Set a new cloud speed
 eval(cloudid).cloudspeed=Math.random()*cloudspeedvariance+cloudminspeed; 
}

  同样办法再新建立一个草的影片剪辑

Flash AS 实现好看的清晰的飘动云和风吹草动画

  选择第一帧添加如下代码。

//Height of each blade of grass
grassheight=35;
//Average space in between each blade of grass
grassspacing=5;
//Maximum sway of each blade of grass
maxsway=20;
//Number of blades of grass along the x axis
xplots=30;
//Number of blades of grass along the y axis
yplots=20;
//The wind has an x position and the grass is attracted to the position
windxpos=0;
//Velocity of the wind left and right
windspeed=0;
//Gives the grass a bent effect. The grass bends 1/4 of the way up
grasscontrol=grassheight/4;
//Array containing the info for each blade of grass
grasscoords=[];
//These loops go through the field, planting each blade of grass
for (xpos=0; xpos for (ypos=0; ypos  //x position, y position, sway, and color
  grasscoords.push([xpos*grassspacing+Math.random()*grassspacing,ypos*grassspacing+Math.random()*grassspacing,0,Math.round(Math.random()*128)*65536+Math.round(Math.random()*76+146)*256]);
 }
}
//Run on each frame
onEnterFrame=function(){
//Clear all of the grass so it can be redrawn with different sway
 this.clear();
//Change the speed of the wind
 windspeed=Math.max(-50,Math.min(50,windspeed+Math.random()*40-20));
//Move the position the blades are attracted according to the windxpos
 windxpos+=windspeed;
//If the windxpos moves too far to the left, reverse its speed
 if(windxpos<-100){
  windxpos=-100;
  windspeed*=-1;
 }
//If the windxpos moves too far to the right, reverse its speed
 else if(windxpos>grassspacing*xplots+100){
  windxpos=grassspacing*xplots+100;
  windspeed*=-1;
 }
//handle the redraw for each blade of grass
 for(coord=0;coord//Set the line style. 0 means use hairline width and grasscoords[coord][3] is the color   
  this.lineStyle(0, grasscoords[coord][3], 100, false, "normal", "none", "none", 1);
//Adjust the sway according to the grass's current sway and the windxpos
  grasscoords[coord][2]=Math.max(-maxsway,Math.min(maxsway,grasscoords[coord][2]+Math.max(-maxsway,Math.min(maxsway,(windxpos-grasscoords[coord][0])/100))))+(Math.random()*3-1.5);
//Move to the base of the blade of grass
  this.moveTo(grasscoords[coord][0],grasscoords[coord][1]);
//Draw a curved line to the new top of the blade of grass
  this.curveTo(grasscoords[coord][0],grasscoords[coord][1]-grasscontrol,grasscoords[coord][0]+grasscoords[coord][2],grasscoords[coord][1]-grassheight+Math.abs(grasscoords[coord][2]/2));
 }
}

  然后回到主场景中,建立两个图层,下面的为云的图层,上面的为草的图层,这里我绘制了一个放草的框框。

Flash AS 实现好看的清晰的飘动云和风吹草动画

  按Ctrl+L打开库分别把草元件和云元件放到相应的图层。给草命名实例grass。

Flash AS 实现好看的清晰的飘动云和风吹草动画

  最后可以测试影片了!但是好象机器运行速度在减慢啊!祝你好运!

技术文章快速查找

栏目导航
软件应用
·操作系统 ·杀毒防黑 ·应用软件
·聊天软件 ·网络软件  
Web开发
·ASP ·JavaScript ·CGI
·JSP ·VbScript ·Web服务器
·PHP ·XML  
开发语言
·VB ·VC ·ASP.NET
·Java ·C/C++ ·Delphi
数据库开发
·MySQL ·SQL/Access ·PowerBuilder
·Oracle ·DB2  
网站设计
·Flash ·Dreamweaver ·HTML/CSS
·Fireworks ·FrontPage  
平面设计
·Photoshop ·CorelDraw ·AutoCAD
·FreeHand ·Illustrator ·3DsMAX
媒体动画
·Director ·Authorware ·Maya
·视频处理    


相关软件 产品库推荐
·笔记本 ·台式机 ·服务器
·数码相机 ·手机 ·GPS
·DV摄像机 ·MP3 ·MP4
·CPU ·硬盘 ·内存
·主板 ·显卡 ·显示器
·打印机 ·投影机 ·路由器

还没人留言,抢个先,哈哈!
对"Flash AS动画实例:风吹云飘草动"的评论 - 快速回贴
内容:
  [完成后可按Ctrl+Enter发布]

百度中 Flash AS动画实例:风吹云飘草动 相关内容
Google搜索中 Flash AS动画实例:风吹云飘草动 相关内容
雅虎中 Flash AS动画实例:风吹云飘草动 相关内容
Sogou搜索中 Flash AS动画实例:风吹云飘草动 相关内容

相关软件 最新回复帖子:

·没有mysql支持时的替代方案
·一个可以发送附件及HTML格式邮件的PHP类
·AutoCAD打造精致三维鸟笼实例详解
·Photoshop自定义水晶字特效样式
·AutoCAD三维基础实例教程
·PS为黑背景长发美女照片抠图换背
·用Photoshop自制个性摩托车贴花小经验
·轻松几步将美女照片处理为手工素描
·巧用Photoshop画笔轻松绘制创意特效
·用Photoshop通道将模糊肖像照片清晰化


  相关软件 Flash AS动画实例:风吹云飘草动相关文章
Flash 动画人物角色行走的几种实现方式 Flash AS代码制作鼠标触发图片缓冲放缩
精简Flash文件体积的几个小技巧 编写Flash AS代码实现按钮触发全屏动画
Flash片头加载loading与V2组件讨论 Flash中定点移动的解决方案分析
Flash加载外部文件的各种方法与技巧 Flash动画制作过程概述及时间控制技巧
Flash动画技巧:动画人物走路的动作规律 Flash电子杂志常用滚动区域控制代码
在Mozilla和Firefox中实现Flash透明背景 Flash的动态文本如何调用外部文本文件
让Flash调用符合web标准 消除浏览器影响 Flash AS代码实例:仿贝塞尔曲线控制
用Flash AS3制作统计饼图动画效果 用Flash AS代码制作按钮弹出窗口
Flash绘画实例:卡通女孩头像 让Flash动画适应任何分辨率的网页
深入了解Flash AS中的setInterval方法 关于Flash中注册点与中心点的区别