【问题标题】:Particle system on AS3, using flash, problem copying the particle elementAS3上的粒子系统,使用flash,复制粒子元素时出现问题
【发布时间】:2011-01-12 01:41:02
【问题描述】:

我在 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 值。有任何想法吗?谢谢!

【问题讨论】:

    标签: flash actionscript-3 particles


    【解决方案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 值。

    【讨论】:

    • 对不起,这对于我的 AS3 级别来说非常复杂,这个 (d.pr/ZiW9) 是我的 .fla,经过你的修改,但我不能产生多个粒子,非常感谢!
    • 查看我对 droplr 链接的编辑,该链接返回到您修改过的文件
    猜你喜欢
    • 2021-07-12
    • 1970-01-01
    • 2011-02-09
    • 1970-01-01
    • 1970-01-01
    • 2012-06-28
    • 1970-01-01
    • 1970-01-01
    • 2013-07-12
    相关资源
    最近更新 更多