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

    • CommentAuthorjungalero
    • CommentTimeJul 9th 2011 edited
     
    Forgive me if this has been covered, but I haven't found the exact approach I'm looking for.

    Put simply, I want to combine the explode image and logo tween examples so I have an image that tweens to a BitmapDataZone on click.

    However, the emitter populated with createRectangleParticlesFromBitmapData doesn't seem to respond to TweenToZone. I'm sure I'm missing something, but what?

    import org.flintparticles.common.events.EmitterEvent;
    import org.flintparticles.common.particles.Particle;
    import org.flintparticles.twoD.actions.DeathZone;
    import org.flintparticles.twoD.actions.Explosion;
    import org.flintparticles.twoD.actions.Move;
    import org.flintparticles.twoD.actions.MouseGravity;
    import org.flintparticles.twoD.actions.GravityWell;
    import org.flintparticles.twoD.emitters.Emitter2D;
    import org.flintparticles.twoD.particles.Particle2DUtils;
    import org.flintparticles.twoD.renderers.DisplayObjectRenderer;
    import org.flintparticles.twoD.zones.RectangleZone;
    import org.flintparticles.twoD.actions.TweenToZone;
    import org.flintparticles.twoD.zones.BitmapDataZone;


    var explosion:Explosion;
    var bitmap:BitmapData = new Image1( 384, 255 );
    var particlesImage:BitmapData = new ParticlesImage( 320, 80 );

    var emitter:Emitter2D = new Emitter2D();
    emitter.addAction( new Move() );
    emitter.addAction( new DeathZone( new RectangleZone( -10, -10, 510, 360 ), true ) );
    prepare();

    var renderer:DisplayObjectRenderer = new DisplayObjectRenderer();
    addChild( renderer );
    renderer.addEmitter( emitter );
    emitter.start();

    stage.addEventListener( MouseEvent.CLICK, explode, false, 0, true );
    emitter.addEventListener( EmitterEvent.EMITTER_EMPTY, prepare );

    function prepare( event:EmitterEvent = null ):void
    {
    if( explosion )
    {
    emitter.removeAction( explosion );
    explosion = null;
    }
    var particles:Vector.<Particle> = Particle2DUtils.createRectangleParticlesFromBitmapData( bitmap, 8, emitter.particleFactory, 0, 0 );
    emitter.addParticles( particles, false );
    }

    function explode( ev:MouseEvent ):void
    {
    var p:Point = renderer.globalToLocal( new Point( ev.stageX, ev.stageY ) );

    if (!explosion) {
    explosion = new Explosion( 2,p.x, p.y, 500 );
    //emitter.addAction( explosion );
    //emitter.addAction(new MouseGravity(50, stage, 50));
    emitter.addAction( new TweenToZone( new BitmapDataZone( particlesImage, 40, 60 ) ) );
    } else {
    //emitter.addAction( new GravityWell( 50, p.x, p.y ) );
    }
    }
    • CommentAuthorRichard
    • CommentTimeJul 31st 2011
     
    This doesn't work as you've coded it because TweenToZone requires the particle to have a lifetime and an age action. The easiest way to achieve what you want is like this

    import org.flintparticles.common.actions.Age;
    import org.flintparticles.common.initializers.Lifetime;
    import org.flintparticles.common.particles.Particle;
    import org.flintparticles.twoD.actions.TweenToZone;
    import org.flintparticles.twoD.emitters.Emitter2D;
    import org.flintparticles.twoD.particles.Particle2DUtils;
    import org.flintparticles.twoD.renderers.DisplayObjectRenderer;
    import org.flintparticles.twoD.zones.BitmapDataZone;

    var bitmap : BitmapData = new Image1( 384, 255 );
    var particlesImage : BitmapData = new ParticlesImage( 320, 80 );
    var emitter : Emitter2D = new Emitter2D();
    emitter.addInitializer( new Lifetime( 6 ) );
    emitter.addAction( new Age() );
    emitter.addAction( new TweenToZone( new BitmapDataZone( particlesImage, 40, 60 ) ) );

    var particles : Vector.<Particle> = Particle2DUtils.createRectangleParticlesFromBitmapData( bitmap, 8, emitter.particleFactory, 0, 0 );
    emitter.addParticles( particles, true );

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

    stage.addEventListener( MouseEvent.CLICK, start, false, 0, true );

    function start( ev : MouseEvent ) : void
    {
    emitter.start();
    }