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

    • CommentAuthoradeetza
    • CommentTimeDec 13th 2011 edited
     
    Hi guys,
    I'm trying to build a snow-like project but I want to use self-animating Sprites instead of images as particles.
    There is a Sprite object inside the Library with the linkage identifier of Balloon.

    package
    {
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.geom.Point;
    import org.flintparticles.common.counters.*;
    import org.flintparticles.common.displayObjects.RadialDot;
    import org.flintparticles.common.initializers.*;
    import org.flintparticles.twoD.actions.*;
    import org.flintparticles.twoD.emitters.Emitter2D;
    import org.flintparticles.twoD.initializers.*;
    import org.flintparticles.twoD.particles.Particle2D;
    import org.flintparticles.twoD.particles.Particle2DUtils;
    import org.flintparticles.twoD.renderers.*;
    import org.flintparticles.twoD.zones.*;

    /**
    * ...
    * @author Eugene
    */
    public class snow extends MovieClip
    {
    private var emitter:Emitter2D;
    private var renderer:DisplayObjectRenderer;
    private var dzone:RectangleZone;
    private var deathZone:DeathZone;

    //init effect
    public function snow()
    {
    emitter = new Emitter2D();
    emitter.counter = new Steady(30);

    var balPart:Particle2D = Particle2DUtils.createParticle2DFromDisplayObject(new Balloon());
    emitter.addParticle(balPart);

    emitter.addInitializer( new Position( new LineZone( new Point( -5, -5 ), new Point( 720, -5 ) ) ) );
    emitter.addInitializer( new Velocity( new PointZone( new Point( 30, 120 ) ) ) );
    emitter.addInitializer( new ScaleImageInit( 0.5, 4 ) );

    dzone = new RectangleZone( -10, -10, 740, 420 );
    deathZone = new DeathZone( dzone, true );
    emitter.addAction( deathZone );
    emitter.addAction(new Move());
    emitter.addAction( new RandomDrift( 110, 10 ));

    renderer = new DisplayObjectRenderer();
    renderer.addEmitter(emitter);
    addChild(renderer);

    emitter.runAhead(10);

    emitter.start();
    }

    public function removeEffect() //clean up ram from loader
    {
    emitter.stop();
    renderer.removeEmitter(emitter);
    emitter.killAllParticles();
    emitter = null;
    removeChild(renderer);
    }
    }
    }


    Any thoughts?

    Thanks in advance!
    • CommentAuthoradeetza
    • CommentTimeDec 14th 2011
     
    Any help please?
    • CommentAuthorRichard
    • CommentTimeDec 14th 2011 edited
     
    You don't say what exactly isn't working, but on a brief look at your code it looks like you're only creating one particle, and adding it before you add all the actions to the emitter. Don't use Particle2DUtils.createParticle2DFromDisplayObject. Use the ImageClass initializer, as used in this example, but pass it your custom class as the image initializer

    emitter.addInitializer( new ImageClass( Balloon ) );
    This initializer will create a new instance of your custom class for each particle.
    • CommentAuthoradeetza
    • CommentTimeDec 15th 2011
     
    Thanks for your help, Richard! It works perfectly now! I was afraid I'd lost the animation that occurs inside the Balloon objects (which basically extends the Sprite class but also contains several MovieClip objects having certain timeline animations) if I used the ImageClass initializer. Now I'm happy I was wrong :)

    Again, many thanks for pointing me to the right direction, Richard!
    • CommentAuthoradeetza
    • CommentTimeDec 15th 2011
     
    By the way... how can I format the code blocks here on the forums so that my code can keep the indentation?
    • CommentAuthorRichard
    • CommentTimeDec 20th 2011
     
    To add code blocks as code, place the code inside <code> elements, and tick the "html" box beneath the comments box.