Fork me on GitHub
Not signed in (Sign In)
    • CommentAuthormafsays
    • CommentTimeJun 29th 2011
     
    so i have an emitter and I'm adding a CollisionZone, and listening for ZONE_COLLISION events - I want to remove the particles when they hit the collision zone:

    var rect : Rectangle = new Rectangle( 100, 300, 400, 30 );
    emitter.addAction( new CollisionZone( new RectangleZone( rect.x, rect.y, rect.x + rect.width, rect.y + rect.height ) ) );
    emitter.addEventListener( ParticleEvent.ZONE_COLLISION, onZoneCollision );

    protected function onZoneCollision( e : ParticleEvent ) : void
    {
    var particle : Particle2D = Particle2D( e.particle );
    emitter.removeParticle( particle );
    }

    this all works, but the update loop continues to try and reference the particle i've removed and i therefore get a null reference error - at what point is it safe to remove a particle to avoid this, or what's the best way to approach removing a particle based on an event dispatched during the update loop?
    • CommentAuthormafsays
    • CommentTimeJun 29th 2011
     
    have gone for:

    protected function onZoneCollision( e : ParticleEvent ) : void
    {
    var particle : Particle2D = Particle2D( e.particle );
    particle.isDead = true;
    }

    this then lets the emitter take care of clearing up the particle. Still be interested to hear when, if ever, removeParticle() is a valid call to make - it doesn't seem to remove the particle as effectively as the code in update()
    • CommentAuthorRichard
    • CommentTimeJul 31st 2011
     
    The conceptual difference between removing a particle (emitter.removeParticle(particle)) and killing the particle (particle.isDead=true) is, in the former case the assumption is that you don't want to kill the particle (you may, for example, be transferring it to a different emitter).

    As you point out, removeParticle doesn't work correctly during the update cycle. I've just now fixed this, and checked the fix into the github repository.

    Which you should be using depends on whether you actually want to kill the particle or just remove it from the emitter and place it elsewhere.
    • CommentAuthorSimoensS
    • CommentTimeAug 1st 2011
     
    Is this new version the same one as on the download page ? I'm having the same problem and after redownloading the source code it still throws the null pointer exception error.

    I want particles that have collided with a collision zone to stay where they are, so I removed them from the emitter expecting them to stay without being updated.
    Is there another better way to stop certain particles from being updated, for example an ignore property ?
    • CommentAuthorRichard
    • CommentTimeAug 6th 2011 edited
     
    No, it isn't in a formal release yet. Until it is, the only way to get the revised code it is to use git to checkout the github repository.