Flint Particle System Forum - Changing the alpha of a particle on PARTICLES_COLLISION Tue, 13 Dec 2011 11:03:59 +0000 http://flintparticles.org/forum/ Lussumo Vanilla 1.1.10 & Feed Publisher Changing the alpha of a particle on PARTICLES_COLLISION http://flintparticles.org/forum/comments.php?DiscussionID=479&Focus=1620#Comment_1620 http://flintparticles.org/forum/comments.php?DiscussionID=479&Focus=1620#Comment_1620 Thu, 28 Apr 2011 18:21:14 +0100 chien
Should I be taking another approach?

Thanks,

CEH ]]>
Changing the alpha of a particle on PARTICLES_COLLISION http://flintparticles.org/forum/comments.php?DiscussionID=479&Focus=1624#Comment_1624 http://flintparticles.org/forum/comments.php?DiscussionID=479&Focus=1624#Comment_1624 Sat, 30 Apr 2011 18:14:27 +0100 chien
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( ); ]]>
Changing the alpha of a particle on PARTICLES_COLLISION http://flintparticles.org/forum/comments.php?DiscussionID=479&Focus=1629#Comment_1629 http://flintparticles.org/forum/comments.php?DiscussionID=479&Focus=1629#Comment_1629 Tue, 03 May 2011 08:51:21 +0100 Richard
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. ]]>
Changing the alpha of a particle on PARTICLES_COLLISION http://flintparticles.org/forum/comments.php?DiscussionID=479&Focus=1632#Comment_1632 http://flintparticles.org/forum/comments.php?DiscussionID=479&Focus=1632#Comment_1632 Tue, 03 May 2011 09:53:52 +0100 chien