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

    • CommentAuthorchien
    • CommentTimeApr 28th 2011
     
    I am trying to reveal an object as the emitter passes over portions of it. the closest analogy I can think of is real time writing. However in trying to change the alpha I get a read only error.

    Should I be taking another approach?

    Thanks,

    CEH
    • CommentAuthorchien
    • CommentTimeApr 30th 2011 edited
     
    I guess it's going to be more complicated. I just realized that I am not getting collisions using one renderer and 2 emitters.

    what I need is to have detection of the particles between the two emitters and be able to manipulate the listened to particle(s). Hopefully this won't create too large an overhead to be possible speed wise.

    import org.flintparticles.common.actions.*;
    import org.flintparticles.common.counters.*;
    import org.flintparticles.common.particles.Particle;
    import org.flintparticles.common.displayObjects.Line;
    import org.flintparticles.common.initializers.*;
    import org.flintparticles.common.initializers.CollisionRadiusInit;
    import org.flintparticles.common.events.ParticleEvent;
    import org.flintparticles.twoD.actions.*;
    import org.flintparticles.twoD.activities.FollowMouse;
    import org.flintparticles.twoD.emitters.Emitter2D;
    import org.flintparticles.twoD.particles.*;
    import org.flintparticles.twoD.initializers.*;
    import org.flintparticles.twoD.renderers.*;
    import org.flintparticles.twoD.zones.*;

    import flash.display.*;
    import flash.events.*;

    var emitter:Emitter2D = new Emitter2D();
    var emitter1:Emitter2D = new Emitter2D();
    var boxArray:Array = new Array();
    var box:Sprite = new Sprite();

    box.graphics.beginFill(0x800000);
    box.graphics.drawPath(
    Vector.([1,2,2,2,2]),
    Vector.([10,10, 100,10, 100,100, 10,100, 10,10]));
    boxArray[0] = box;

    emitter.counter = new Steady( 150 );

    emitter.addInitializer(new CollisionRadiusInit(5));
    emitter.addInitializer( new SharedImage( new Line( 8 ) ) );
    emitter.addInitializer( new ColorInit( 0xFFFFCC00, 0xFFFFCC00 ) );
    emitter.addInitializer( new Velocity( new DiscZone( new Point( 0, 0 ), 350, 200 ) ) );
    emitter.addInitializer( new Lifetime( 0.2, 0.4 ) );

    emitter.addAction( new Age() );
    emitter.addAction( new Move() );
    emitter.addAction( new RotateToDirection() );

    emitter1.addInitializer(new CollisionRadiusInit(5));

    var renderer:BitmapRenderer = new BitmapRenderer( new Rectangle( 0, 0, 400, 400 ) );
    renderer.addFilter( new BlurFilter( 2, 2, 1 ) );
    renderer.addFilter( new ColorMatrixFilter( [ 1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0.95,0 ] ) );
    renderer.addEmitter( emitter );
    addChild( renderer );

    var particles:Vector. = Particle2DUtils.createParticles2DFromDisplayObjects( boxArray, renderer ,emitter1.particleFactory );
    emitter1.addParticles( particles, false );
    renderer.addEmitter(emitter1);
    emitter.addActivity( new FollowMouse( renderer ) );
    emitter1.addEventListener( ParticleEvent.PARTICLES_COLLISION, alphaParticle );
    emitter.addEventListener( ParticleEvent.PARTICLES_COLLISION, alphaParticle );

    function alphaParticle( event:ParticleEvent ):void {

    trace("Alpha: " + event.particle.alpha);
    }

    emitter.start( );
    • CommentAuthorRichard
    • CommentTimeMay 3rd 2011
     
    Particles store their alpha as part of the color property (color is a 32-bit argb value). There is a read-only alpha property to get the alpha part from the color, but there is no setter.

    To set the alpha, you set the top 8 bits of the color property of the particle. In practice this means you make the particle fully opaque using

    particle.color = particle.color | 0xFF000000;

    and you make the particle fully transparent using

    particle.color = particle.color & 0x00FFFFFF;

    For collisions, as you realised the collision action only handles collisions between particles that are on the same emitter. You may be able to place all your particles on one emitter. For example, if you give the particles on emitter1 a very large lifetime, so effectively they will not die, then they could possibly be placed on emitter 0 along with the other particles. The other option is to create a custom action to handle collisions between particles on multiple emitters. The source code for the existing Collide action could be a useful start point for this.
    • CommentAuthorchien
    • CommentTimeMay 3rd 2011
     
    Ok, thanks Richard. My latest test put all the particles on one emitter but after reading your explanation I don't think I went far enough.