0

我在 AS3 中开发了一个非常简单的粒子系统,我有粒子(电影剪辑)和粒子行为,但现在我需要一个很好的方法来复制它 n 次并更改确定系统行为的唯一值,宽度,从 10 到 100 像素。

这是代码:

//some declarations
var blur:BlurFilter = new BlurFilter();
var filterArray:Array = new Array(blur);
import fl.transitions.Tween;
import fl.transitions.easing.*;

//the only input value, from 10 to 100
par.width=100;
//the equations that define the behavior.
par.alpha=.0088*par.width+.98;
par.height=par.width;
blur.blurX = .75*par.width-.55;
blur.blurY = blur.blurX;
blur.quality = 1;
par.filters = filterArray;
//the movement of the particle
var myTween:Tween = new Tween(par, "y", Strong.easeOut, par.y, stage.stageHeight+2*par.height, -.2*par.width+22, true); 

因此,如您所见,par是粒子的实例名称,好吧,我需要复制它以更改 .width 值并最终更改 .x 值。有任何想法吗?谢谢!

4

1 回答 1

1

这就是 OOP(面向对象编程)的全部内容,Flash 就是一个很好的例子。

package  {

    import flash.filters.BlurFilter;
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    import flash.display.MovieClip;
    import flash.events.Event;

    public class Particle extends MovieClip {

        public function Particle() {
            // constructor code
            //some declarations
            this.graphics.beginFill(0, 1);
            this.graphics.drawCircle(0, 0, 50);
            var blur:BlurFilter = new BlurFilter();
            var filterArray:Array = new Array(blur);
            //the only input value, from 10 to 100
            this.width = Math.round(Math.random() * 90) + 10;
            //the equations that define the behavior.
            this.alpha = .0088 * this.width + .98;
            this.height = this.width;
            blur.blurX = .75 * this.width - .55;
            blur.blurY = blur.blurX;
            blur.quality = 1;
            this.filters = filterArray;
            this.addEventListener(Event.ADDED_TO_STAGE, __tweenMe);
        } 


        private function __tweenMe($evt:Event):void {
            //the movement of the particle
            var myTween:Tween = new Tween(this, "y", Strong.easeOut, this.y, stage.stageHeight+2*this.height, -.2*this.width+22, true); 
        }

    }

}

然后在您的 DocumentClass 中,您可以执行以下操作:

package  {

    import flash.display.MovieClip;

    public class BaseClass extends MovieClip {

        public function BaseClass() {
        var par:Particle;
            for ( var i:int = 0; i < 100; i++) {
                par = new Particle();
                addChild(par);
            }       
        }   
    }    
}

编辑

你去http://d.pr/ycUh。如果您对正在发生的事情有任何疑问,请告诉我。我为粒子的起始位置添加了一些随机 x 和 y 值。

于 2011-01-11T06:11:54.753 回答