Welcome, Guest
Want to take part in these discussions? Sign in if you have an account, or apply for one below
How do I?: Make particles of two emitters to collide, or change emitter counter properties in real time
Bottom of Page1 to 11 of 11
-
-
CommentAuthorifthenelse
- CommentTimeNov 21st 2008 edited
Hello again, I'm stucked into another problem. What I'm looking for is to:
1. make the emitter shoot a blast of 1000 particles at the application start;
2. and then shot 10 particles every second which will collide with the first 1000 (using the same emitter initializers).
The emitter has a DiscZone position initializer. The particles are accellerated by a GravityWell at the center of the stage with a ZonedAction and then dragged to reach stillness in a circular area at the center.
Hope that these two sketches can help to understand (sorry for the poor quality, but I had no plain support to draw):

I've tried to use two emmiters (the first is a Blast and the second is a Steady) and associate them to an unique renderer, but their respective particles don't collide.
Then, I've tried to use a Pulse emitter and assigning its quantity and period to two variables, regulated by the getTimer() function (which gives the milliseconds since the application started), but I can't make them change value. Moreover getTimer() is affected by growing latency.
Is there a way to make the particles generated by two different emitters to collide? Or to make the emitter counter properties change in real-time? Also, suggestions for alternative ways are welcome. Thanks! -
-
- CommentAuthorpsilos
- CommentTimeNov 21st 2008 edited
T -
-
CommentAuthorifthenelse
- CommentTimeNov 21st 2008 edited
I tried with a Steady counter shooting 10 particle per second and then putting emitter.runAhead(100); but in this way the intial circle is already built. Instead, I would like to, for first, make it with a blast of 1000 particles emitted in the same moment, and then, emit 10 particles per second which will collide with those that were shot previously. -
-
- CommentAuthorpsilos
- CommentTimeNov 21st 2008
You are right, I thought that right after i posted. :) -
- CommentAuthoralphagod
- CommentTimeNov 23rd 2008 edited
Can't you just call the start() method again after changing the counter? Like for example I use
emitter.counter = new PerformanceAdjusted(4, 100, 33);
//initialize properties
emitter.start();
and then
emitter.counter = new Steady(500);
emitter.start();
Works as it should and changes whenever it needs to. -
-
CommentAuthorifthenelse
- CommentTimeNov 23rd 2008
Yes, thank you very much alphagod, you're right! -
-
- CommentAuthorRichard
- CommentTimeNov 23rd 2008 edited
The need to restart the emitter is a mistake and shouldnot have been necessary. I've just checked a fix into SVN. Without the fix it is as alphagod said. With the fix you just...emitter.counter = new Blast( 1000 );
//initialize properties
emitter.start();
and thenemitter.counter = new Steady( 10 ); -
-
CommentAuthorifthenelse
- CommentTimeNov 25th 2008 edited
Thank you Richard too. Unfortunately I'm not so much into SVN, I've retrieved the files with TurtleSVN, but I don't know how to check their version and to make an extension package for Flash. Anyway I have been in a hurry, so I used the 2.0.0. Please, forgive me, but I'm a true noob. So, by the moment, I used the method suggested by alphagod.
Everything works good, but, there's something that doesn't add up: the two counters are associated to two seprate initializerGroup (blastGroup and pAGroup) and, since they're actually equal (except for different Lifetime values), the respective particles are supposed to be generated in the same area (precisely on a ring outside the stage). Instead, those of the PerformanceAdjusted emitter are generated in a random position both in and out of bounds.
I checked the code and run it at least 50 times, also changing the second counter with a Steady, but the result doesn't change. I really don't understand where the problem is. Perhaps can you glance at it? Heres the code, if anybody that wants to make a test. It is not the whole job... this just contains the data about particles.
/*Importing libraries*/
import flash.utils.getTimer;
import flash.display.StageScaleMode;
import flash.geom.Point;
import org.flintparticles.common.actions.*;
import org.flintparticles.common.energyEasing.*;
import org.flintparticles.common.counters.*;
import org.flintparticles.common.displayObjects.Dot;
import org.flintparticles.common.initializers.*;
import org.flintparticles.twoD.actions.*;
import org.flintparticles.twoD.emitters.Emitter2D;
import org.flintparticles.twoD.initializers.*;
import org.flintparticles.twoD.renderers.*;
import org.flintparticles.twoD.zones.*;
/*Tells how to build emitter counter according to the time passed*/
function timeCount(event:TimerEvent):void
{
var timeStore:uint;
timeStore = getTimer();
//trace( "timeCount() called @ " + timeStore + " ms" );
if( timeStore < 2000 )
{
emitter.counter = new Blast( 1000 );
emitter.addInitializer( new ChooseInitializer( [ blastGroup ] ) );
emitter.start();
}
else
{
if( timeStore > 26000 )
{
myTimer.stop();
myTimer.removeEventListener( TimerEvent.TIMER, timeCount );
emitter.counter = new PerformanceAdjusted( 8, 11, 60 );
emitter.addInitializer( new ChooseInitializer( [ pAGroup ] ) );
emitter.start();
}
}
}
/*Stage Resizer to keep aspect ratio*/
stage.scaleMode = StageScaleMode.SHOW_ALL;
/*Declaring emitters*/
var particleRadius:Number = 7;
var emitter:Emitter2D = new Emitter2D();
/*Declaring colors*/
var color1:uint = 0xFFFF1234;
var color2:uint = 0xFF12FF34;
var color3:uint = 0xFF1234FF;
/*Building colors array*/
var colorsArray:Array = [ color1, color2, color3 ];
/*Declaring geometric variables*/
var hCenter:Number = stage.stageWidth * 0.5;
var vCenter:Number = stage.stageHeight * 0.5;
var startRadiusMax:Number = ( stage.stageWidth * 0.5 * 1.8 );
var startRadiusMin:Number = ( stage.stageWidth * 0.5 * 1.1 );
/*Setting timer variable and its delay*/
var myTimer:Timer = new Timer(1000);
myTimer.start();
/*Initializers group for the Blast counter*/
var blastGroup:InitializerGroup = new InitializerGroup();
blastGroup.addInitializer( new ImageClass( Dot, particleRadius ) );
blastGroup.addInitializer( new ColorsInit( colorsArray ) );
blastGroup.addInitializer( new Lifetime( 150, 600 ) );
blastGroup.addInitializer( new MassInit( particleRadius ) );
blastGroup.addInitializer( new CollisionRadiusInit( particleRadius ) );
blastGroup.addInitializer( new Position( new DiscZone( new Point( hCenter, vCenter ), startRadiusMax, startRadiusMin ) ) );
/*Initializers group for the PerformanceAdjusted counter*/
var pAGroup:InitializerGroup = new InitializerGroup();
pAGroup.addInitializer( new ImageClass( Dot, particleRadius ) );
pAGroup.addInitializer( new ColorsInit( colorsArray ) );
pAGroup.addInitializer( new Lifetime( 480, 660 ) );
pAGroup.addInitializer( new MassInit( particleRadius ) );
pAGroup.addInitializer( new CollisionRadiusInit( particleRadius ) );
pAGroup.addInitializer( new Position( new DiscZone( new Point( hCenter, vCenter ), startRadiusMax, startRadiusMin ) ) );
/*Defining emitter actions*/
emitter.addAction( new Move() );
emitter.addAction( new Age() );
emitter.addAction( new Collide( 0.1 ) );
emitter.addAction( new ZonedAction( new GravityWell( 900, hCenter, vCenter, startRadiusMax+100 ), new DiscZone( new Point( hCenter, vCenter ), startRadiusMax+100, stage.stageWidth * 0.15 ) ) );
emitter.addAction( new LinearDrag( 0.88 ) );
/*Render initializations*/
var renderer:DisplayObjectRenderer = new DisplayObjectRenderer();
addChild( renderer );
renderer.addEmitter( emitter );
/*Time Event Listener*/
myTimer.addEventListener(TimerEvent.TIMER, timeCount); -
-
- CommentAuthoralphagod
- CommentTimeNov 25th 2008 edited
I'm not really sure on this but it seems to me as you are adding more and more initializers without removing the previous ones, this may be the reason. Try removing the other previous initializer group before adding the new one with removeInitializer() also you should declare each initializer as a variable before using it for example instead of addInitializer( new Lifetime( 480, 660 ) ); you should have:
var lifeTime:Lifetime = new Lifetime( 480, 660 );
addInitializer( lifeTime );
this way you can remove an initializer later with removeInitializer(lifeTime); this way you also would have less intializer objects at the end as you just change the already created ones values not create whole new ones and add them to the emitter. I can't check your code because I'm not on a machine with flash on but this may be the reason for the different results.
As for using the svn it's very simple, just move the entire org folder somewhere within your class path and you can access it just like before. -
-
CommentAuthorifthenelse
- CommentTimeDec 1st 2008
Yeah you're right. As you suggested the two initializerGroup have been removed and every initializer is declared as variables. This way, to change the lifeTime of particles, I simply set its properties (minLifetime and maxLifetime) with two new values. That works nicely. Exactly as I expected in my mind. Also I've been able to substitute the new flintParticles build over the older one. Indeed it was much easier than expected. So, thanks a lot! -
-
- CommentAuthorRichard
- CommentTimeDec 1st 2008
Pleased you got it sorted, and alphagod - thanks for helping out.
1 to 11 of 11
