• 微课视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
微课江湖
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 微课视频
  • photoshop
  • Fireworks
  • CorelDraw
  • Illustrator
  • Painter
  • Freehand
  • Indesign
  • flash
  • maya
  • autocad
  • 3dmax
您的位置:首页 > 平面设计 >flash > Flash AS3 连锁反应的粒子动画

Flash AS3 连锁反应的粒子动画

作者:佚名 字体:[增加 减小] 来源:互联网 时间:2017-05-24

佚名 向大家分享了Flash AS3 连锁反应的粒子动画,其中包含flash as3教程,flash as3 api,flash as3帮助,flash as3视频教程,flash游戏修改器as3等知识点,遇到此问题的同学们可以参考下
这是一个粒子效果实例教程,将学习如何创建粒子并产生一个连锁反应。

演示:


1、新建Flash文档,设置:宽、高为 400 × 400 ,保存。

2、用椭圆工具在舞台上画一个 20 × 20 大小的圆。 (你能选择任意的颜色)

3、右键单击圆形,把它转换成影片剪辑,注册点居中。

4、在ActionScript导出的复选框中打勾 ,做类链接,类名为" Particle " 。图1:

5、把圆形从舞台删除,新建ActionScript 3.0文件。图2:

6、我们编写一个外部的Particle类。在编译器中输入代码:

package{



importflash.display.MovieClip;



publicclassParticleextendsMovieClip{



//Weneeddifferentspeedsfordifferentparticles.

//Thesevariablescanbeaccessedfromthemainmovie,becausetheyarepublic.

publicvarspeedX:Number;

publicvarspeedY:Number;

publicvarpartOfExplosion:Boolean=false;



functionParticle():void{



}

}

}

7、保存在fla文件的同一目录下,名为 " Particle " 。图3:

8、切换到我们的fla主文档。首先我们在舞台上生成粒子实例。在第一帧输入代码:

//Weneedfewimportsforthecolor

importfl.motion.Color;

importflash.geom.ColorTransform;

/*Wewant20particlesatthestart

particlesArrayisusedwhenweanimateeachparticle*/

varnumberOfParticles:Number=20;

varparticlesArray:Array=newArray();

//Eachtimeahitoccurs,wewanttocreate10newparticles

varnumberOfExplosionParticles:uint=10;

//Thisloopcreatesthefirstparticlesandgivesthemspeedandcoordinates

for(vari=0;i<numberOfParticles;i++){

varparticle:Particle=newParticle();

//Wewanttheparticlestostayattheiroriginalposition

particle.speedX=0;

particle.speedY=0;

//Setthestartingposition

particle.y=Math.random()*stage.stageHeight;

particle.x=Math.random()*stage.stageWidth;

//Addtheparticletothestageandpushittoarrayforlateruse.

addChild(particle);

particlesArray.push(particle);

}

9、测试你的影片,效果如图。图4:

10、随机地选择一个粒子产生爆炸效果。爆炸后,生成新的粒子。最后,删除舞台上爆炸的粒子。把下列代码块加入到动作面板:

//Callforthefirstexplosion

startExplosions();

/*Thisfunctionmakesarandomparticletoexplode.

Fromhere,thechainreactionbegins.*/

functionstartExplosions():void{

//Selectarandomparticlefromanarray

varindex=Math.round(Math.random()*(particlesArray.length-1));

varfirstParticle:Particle=particlesArray[index];

//Setarandomtint

varct:Color=newColor();

ct.setTint(0xFFFFFF*Math.random(),1);

//Create10newparticlesbecauseofexplosion

for(vari=0;i<numberOfExplosionParticles;i++){

varparticle:Particle=newParticle();

/*Giverandomxandyspeedtotheparticle.

Math.randomreturnsarandomnumbern,where0<=n<1.*/

particle.speedX=Math.random()*10-5;

particle.speedY=Math.random()*10-5;

//Applytherandomlyselectedtinttoeachparticle

particle.transform.colorTransform=ct;

//Setthestartingposition

particle.y=firstParticle.y;

particle.x=firstParticle.x;

//Particleispartofanexplosion

particle.partOfExplosion=true;

//Addtheparticletothestageandpushittoarrayforlateruse.

addChild(particle);

particlesArray.push(particle);

}

//Let’sremovetheparticlethatexploded(removefromstageandfromthearray)

removeChild(firstParticle);

particlesArray.splice(index,1);

addEventListener(Event.ENTER_FRAME,enterFrameHandler);

}

11、添加方法 enterFrameHandler,更新粒子坐标,使粒子动起来。输入下列代码:

//Thisfunctionisresponsiblefortheanimation

functionenterFrameHandler(e:Event):void{

//Loopthrougheveryparticle

for(vari=0;i<particlesArray.length;i++){

varparticleOne:Particle=particlesArray[i];

//Updatetheparticle’scoordinates

particleOne.y+=particleOne.speedY;

particleOne.x+=particleOne.speedX;

/*ThisloopcallsacheckForHitfunctiontofindifthetwoparticlesarecolliding*/

for(varj:uint=i+1;j<particlesArray.length;j++){

varparticleTwo:Particle=particlesArray[j];

/*Makesuretheparticlesareonstage,onlythencheckforhits*/

if(contains(particleOne)&&contains(particleTwo)){

checkForHit(particleOne,particleTwo);

}

}

}

}

12、方法 " checkForHit" 是最难的部份,碰撞检测。输入代码:

/*Thisfunctioncheckswhethertwoparticleshavecollided*/

functioncheckForHit(particleOne:Particle,particleTwo:Particle):void{

/*Let’smakesureweonlycheckthoseparticles,whereoneismovingandtheother

isstationary.Wedon’twanttwomovingparticlestoexplode.*/

if((particleOne.partOfExplosion==false&&particleTwo.partOfExplosion==true)||

particleOne.partOfExplosion==true&&particleTwo.partOfExplosion==false){

//CalculatethedistanceusingPythagoreantheorem

vardistanceX:Number=particleOne.x-particleTwo.x;

vardistanceY:Number=particleOne.y-particleTwo.y;

vardistance:Number=Math.sqrt(distanceX*distanceX+distanceY*distanceY);

/*Ifthedistanceissmallerthanparticle’swidth,wehaveahit.

Note:iftheparticleswereofdifferentsize,thecalculationwouldbe:

distance<((particleOne.width/2)+(particleTwo.width/2))

*/

if(distance<particleOne.width){

//Setarandomtinttotheparticlesthatexplode

varct:Color=newColor();

ct.setTint(0xFFFFFF*Math.random(),1);

//Create10newparticlesbecauseofanexplosion

for(vari=0;i<numberOfExplosionParticles;i++){

varparticle:Particle=newParticle();

particle.speedX=Math.random()*10-5;

particle.speedY=Math.random()*10-5;

//Applytint

particle.transform.colorT

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • flash文本竖排效果实现as3代码
  • Flash AS3 连锁反应的粒子动画
  • Flash AS3 制作文字飞出动画
  • Flash AS3 快速制作烟雾动画
  • Flash AS3代码实现鼠标跟随喷枪涂鸦效果
  • Flash AS3的parameters对象处理网页参数
  • FLASH AS3与网页JS参数值传递的问题
  • 从基础开始深入学Flash AS3教程(6)(译文)
  • Flash as3教程:OutDisplay类
  • 从基础开始深入学Flash AS3教程(7)(译文)

相关文章

  • 2017-05-24Flash CS3怎么制作幻灯片轮播的动画?
  • 2017-05-24Flash AS制作LRC歌词同步的详细教程
  • 2017-05-24精简Flash文件体积减肥的7个小技巧
  • 2017-05-24flash8制作漂亮的闪烁文字方法介绍
  • 2017-05-24AS3 结合基本的动画和AS3绘图API
  • 2017-05-24FLASH AS3网站分辨率自适应
  • 2017-05-24Flash AS特效:超绚丽的闪字动画
  • 2017-05-24从基础开始深入学Flash AS3教程(4)(译文)
  • 2017-05-24Flash AS代码编写模拟打字效果的动画特效
  • 2017-05-24教大家如何利用Flash快速制作一个复制功能键

文章分类

  • photoshop
  • Fireworks
  • CorelDraw
  • Illustrator
  • Painter
  • Freehand
  • Indesign
  • flash
  • maya
  • autocad
  • 3dmax

最近更新的内容

    • 关于XML在FLASH中的应用
    • Flash新手教程:跟随鼠标的圈圈动画
    • 彻底消灭Flash动画中的乱码
    • flash随机点名的大转盘该怎么制作?
    • flash逐帧动画制作全过程解析
    • Flash AS3 制作文字飞出动画
    • Flash AS 教程:帧循环
    • 网站中运用Flash技术的优点和缺点
    • 用flash绘制一只飞起来的立体小瓢虫
    • Flash AS 教程:多种图片切换效果

关于我们 - 联系我们 - 免责声明 - 网站地图

©2015-2018 All Rights Reserved. 微课江湖 版权所有