Flint Particle System Forum - Changing the alpha of a particle on PARTICLES_COLLISION 2011-12-13T11:27:32+00:00 http://flintparticles.org/forum/ Lussumo Vanilla & Feed Publisher Changing the alpha of a particle on PARTICLES_COLLISION http://flintparticles.org/forum/comments.php?DiscussionID=479&Focus=1620#Comment_1620 2011-04-28T18:21:14+01:00 2011-12-13T11:27:32+00:00 chien http://flintparticles.org/forum/account.php?u=41 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 ...
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 2011-04-30T18:14:27+01:00 2011-04-30T18:39:21+01:00 chien http://flintparticles.org/forum/account.php?u=41 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 ...
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 2011-05-03T08:51:21+01:00 2011-12-13T11:27:32+00:00 Richard http://flintparticles.org/forum/account.php?u=1 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 ...
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 2011-05-03T09:53:52+01:00 2011-12-13T11:27:32+00:00 chien http://flintparticles.org/forum/account.php?u=41 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.