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 に答える