现在你就可以测试你的影片了。
接下我们要在上面的基出上进行一下变化。看看效果会有什么不同。
我们现在要增加粒子的大小和范围。代码做如下的修改。
代码:
//定义中心位置 var cx = 0; var cy = 0; //设定循环20次,准备从库中复制链接id为partical的影片. for (var i = 0; i<100; i++) { //复制影片剪辑,引用名称为mc. var mc = this.attachMovie("partical", "p"+i, i); with (mc) { //初始化影片剪辑的位置,注意此时cx,cy是用来调整mc实例的偏移位置的. _x = cx+Math.random()*590; _y = cy+Math.random()*350; _xscale = _yscale = 100 * Math.random()*5+1; } //针对mc应用融合模式类型"add" mc.blendMode = "add"; //设定mc实例的角度随机值 mc.tx = random(360); mc.ty = random(360); //设定用于mc角度的增量随机值 mc.xtempo = Math.random()/10; mc.ytempo = Math.random()/10; //设定mc实例的速度随机值 mc.xd = Math.random()*10+1; mc.yd = Math.random()*10+1; mc.x0 = mc._x; mc.y0 = mc._y; //跳转到指定的帧,以变换不同颜色的小球上. mc.gotoAndStop(random(5)+1); //通过onEnterFrame循环,来让粒子移动. mc.onEnterFrame = function() { this.tx += this.xtempo; this.ty += this.ytempo; this._x = this.x0+Math.sin(this.tx)*this.xd; this._y = this.y0+Math.cos(this.ty)*this.yd; }; } |
斜体加粗的代码是我们所修改的位置,我们增加了粒子的数量,同时加入了_xscale._yscale.缩放的随机值,这样便会放大粒子增加粒子的重合度。效果如下。

接下来我们在这段代码的基础上在次进行修改。我们此次要变换一下融合模式,就会得到不同的效果。如下代码。
代码:
//定义中心位置 var cx = 0; var cy = 0; //设定循环20次,准备从库中复制链接id为partical的影片. for (var i = 0; i<100; i++) { //复制影片剪辑,引用名称为mc. var mc = this.attachMovie("partical", "p"+i, i); with (mc) { //初始化影片剪辑的位置,注意此时cx,cy是用来调整mc实例的偏移位置的. _x = cx+Math.random()*590; _y = cy+Math.random()*350; _xscale = _yscale = 140 * Math.random()*5+1; } //针对mc应用融合模式类型"add" mc.blendMode = "hardlight"; mc.cacheAsBitmap = true; //设定mc实例的角度随机值 mc.tx = random(360); mc.ty = random(360); //设定用于mc角度的增量随机值 mc.xtempo = Math.random()/10; mc.ytempo = Math.random()/10; //设定mc实例的速度随机值 mc.xd = Math.random()*10+1; mc.yd = Math.random()*10+1; mc.x0 = mc._x; mc.y0 = mc._y; //跳转到指定的帧,以变换不同颜色的小球上. mc.gotoAndStop(random(5)+1); //通过onEnterFrame循环,来让粒子移动. mc.onEnterFrame = function() { this.tx += this.xtempo; this.ty += this.ytempo; this._x = this.x0+Math.sin(this.tx)*this.xd; this._y = this.y0+Math.cos(this.ty)*this.yd; }; } |
斜体加粗的代码为我们所修改过的位置,我们增大了缩放,同时将融合模式换成了hardlight.当然你可以试一下其它的融合方式,同时我们增加了mc.cacheAsBitmap = true.通过这一句是加速我们的影片剪辑的运算速度。测试的效果如下。