Fork me on GitHub
Not signed in (Sign In)

Welcome, Guest

Want to take part in these discussions? Sign in if you have an account, or apply for one below

    • CommentAuthorrobotz
    • CommentTimeMay 21st 2008
     
    I've been trying to get this working all morning, but to no avail - I think it's a bug (but it might just be the way I'm doing it)

    I wanted to create a single FullStagePixelRenderer that had 10 different emitters working on it.

    I use a for() loop to create 10 emitters, setting random values.

    When all of the emitters are started, only one of them appears rendered.

    However, if you enable a filter on the renderer (such as blur), you can see all of the other emitters running.

    Most confusing! Here is a zip file with the fla and AS code, ready to run.


    /**
    * Mass Emitter Test
    * @author Richard Davey
    * @version 0.1
    */

    package
    {
    import flash.display.Sprite;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import flash.filters.BlurFilter;

    import org.flintparticles.actions.*;
    import org.flintparticles.activities.*;
    import org.flintparticles.counters.*;
    import org.flintparticles.debug.*;
    import org.flintparticles.displayObjects.*;
    import org.flintparticles.emitters.Emitter;
    import org.flintparticles.initializers.*;
    import org.flintparticles.renderers.*;
    import org.flintparticles.utils.*;
    import org.flintparticles.zones.*;

    public class massflint extends Sprite
    {
    private var emitters:Array = new Array();
    private var globalRenderer:FullStagePixelRenderer;

    public function massflint():void
    {
    createRenderer();

    createRandomEmitters();

    addChild(globalRenderer);

    startEmitters();
    }

    private function createRenderer():void
    {
    globalRenderer = new FullStagePixelRenderer();

    globalRenderer.cacheAsBitmap = true;

    // Uncomment the filter and you can see all of the emitters!
    //globalRenderer.addFilter(new BlurFilter(1, 1, 1), false);
    }

    private function createRandomEmitters():void
    {
    var tempEmitter:Emitter;

    for (var i:uint = 0; i < 10; i++)
    {
    trace("Creating Emitter " + i);

    tempEmitter = new Emitter();

    tempEmitter.counter = new Steady(40);
    tempEmitter.renderer = globalRenderer;

    tempEmitter.x = 100 + Math.random() * 350;
    tempEmitter.y = 50 + Math.random() * 300;

    tempEmitter.addInitializer(new ColorInit(0xFFFFFFFF, 0xFFFFFFFF));
    tempEmitter.addInitializer(new Position(new PointZone(new Point(0, 0))));
    tempEmitter.addInitializer(new Velocity(new DiscZone(new Point(0, 0), 100, 250)));
    tempEmitter.addInitializer(new Lifetime(1));

    tempEmitter.addAction(new LinearDrag(1));
    tempEmitter.addAction(new Move());
    tempEmitter.addAction(new Age());

    emitters[i] = tempEmitter;

    tempEmitter = null;
    }
    }

    private function startEmitters():void
    {
    for (var i:uint = 0; i < 10; i++)
    {
    emitters[i].start();
    }
    }
    }
    }


    Any ideas anyone? I'm using Flint 1.0.2.

    Cheers,

    Rich
    • CommentAuthorericr
    • CommentTimeMay 21st 2008
     
    I believe this is because of the "hard-link" between emitter and renderer. Each Emitter assumes that it is the only emitter object associated with the Renderer.

    The Emitter objects, in your case, grab the renderer and wipe out the previous canvas to draw their updated particles. If you specify a blur filter, however, then they don't wipe the canvas clean: they blur the old canvas and then draw on top of it.

    Without the blur filter your 10 emitters are each clearing the renderer and drawing their particles in succession. Thus the last emitter to run is the only one whose pixels you would see represented.

    I believe the concept of associating multiple emitters with a single renderer (and vice versa) is planned for the next version of Flint.

    That said you could easily modify the current code to allow this to work (or even apply the blur filter without actually blurring anything)...
    • CommentAuthorRichard
    • CommentTimeMay 21st 2008
     
    It is as ericr says. Currently you need one renderer per emitter. The next version won't have this restriction.
    • CommentAuthorrobotz
    • CommentTimeMay 21st 2008
     
    I'm both sad that I wasted a morning trying to get this to work, and extremely pleased the next version will cover it :)