Flint Particle System Forum - ParticleFactory with sound spectrum2010-12-25T18:49:03+00:00http://flintparticles.org/forum/
Lussumo Vanilla & Feed Publisher
ParticleFactory with sound spectrumhttp://flintparticles.org/forum/comments.php?DiscussionID=58&Focus=269#Comment_2692008-07-24T17:31:58+01:002010-12-25T18:49:03+00:00icd2k3http://flintparticles.org/forum/account.php?u=46
I was wondering if someone could link me to some kind of example using the particle factory. I seem to be getting my syntax all messed up.
Basically what I'm trying to do is tie in the sound ...
Basically what I'm trying to do is tie in the sound spectrum to a particle generator, so every frame 256 values are calculated and based on the value the program will decide spawn a particle or not. So basic structure:
Enter Frame { for(var i:uint=0; i<256; i++) { soundVar spawn Particle based on soundVar } }
any help would be greatly appreciated, thanks!]]>
ParticleFactory with sound spectrumhttp://flintparticles.org/forum/comments.php?DiscussionID=58&Focus=271#Comment_2712008-07-25T11:51:12+01:002010-12-25T18:49:03+00:00Richardhttp://flintparticles.org/forum/account.php?u=1
Hi
The particle factory is used internally by the Emitter. It just manages the reuse of particles which speeds up the system.
It sounds like what you're after is developing a custom Counter. ...
The particle factory is used internally by the Emitter. It just manages the reuse of particles which speeds up the system.
It sounds like what you're after is developing a custom Counter. Each frame, the counter tells the emitter how many particles to create.
Your custom counter needs to implement the Counter interface, which means it has two methods - startEmitter and updateEmitter. startEmitter is called once, when the emitter starts, and updateEmitter is called every frame while the emitter is running. Each method returns a uint to indicate to the emitter how many particles to create at this time. So in your custom counter, startEmitter would return 0 and updateEmitter would calculate how many particles to spawn based on the sound spectrum and return that value.]]>
ParticleFactory with sound spectrumhttp://flintparticles.org/forum/comments.php?DiscussionID=58&Focus=275#Comment_2752008-07-25T20:20:30+01:002010-12-25T18:49:03+00:00icd2k3http://flintparticles.org/forum/account.php?u=46
Thanks for the response, and for correcting my understanding of the particle factory.
Just to clarify, you mean using something like Steady.as as a starting point and modifying it for my idea ...
Just to clarify, you mean using something like Steady.as as a starting point and modifying it for my idea correct?
Your dedication to this class is insane, I really want to understand it from top to bottom]]>
ParticleFactory with sound spectrumhttp://flintparticles.org/forum/comments.php?DiscussionID=58&Focus=276#Comment_2762008-07-25T21:52:42+01:002010-12-25T18:49:03+00:00icd2k3http://flintparticles.org/forum/account.php?u=46
Ok so, I made my custom counter which spawns 256 particles everytime updateEmitter is called (this will be adjusted later) but it's working. Anyhow, I'm wondering how I can give attributes to each ...
public function updateEmitter( emitter:Emitter, time:Number ):uint { if( _stop ) { return 0; } SoundMixer.computeSpectrum(ba, false); var count:uint = 0; for(var i:uint=0; i<256; i++) { var baNum:Number = ba.readFloat()*200+200; ++count; // adjust each particle based on baNum } return count; }
I've tried things like: emitter.particles[i].energy = baNum; but I guess I'm just not familiar with how it handles things. Thanks again for any help/direction]]>
ParticleFactory with sound spectrumhttp://flintparticles.org/forum/comments.php?DiscussionID=58&Focus=277#Comment_2772008-07-25T22:00:22+01:002008-07-25T22:03:29+01:00icd2k3http://flintparticles.org/forum/account.php?u=46
Just noticed that I can use emitter initializers within the updateEmitter function, but I have a feeling there might be a more effecient method to refer to each spawned particle instead of changing ...
ParticleFactory with sound spectrumhttp://flintparticles.org/forum/comments.php?DiscussionID=58&Focus=280#Comment_2802008-07-27T20:19:13+01:002010-12-25T18:49:03+00:00Richardhttp://flintparticles.org/forum/account.php?u=1
Using an initializer is usually the best way. Alternatives include extending the Emitter class to add your own functionality to the createParticle method or implementing your own particle factory. ...
The counter simply tells the emitter how many particles to create. The emitter then creates all the particles and initializes them in turn by passing each particle to each initializer so the initializer can set its properties.
If you're going to create 256 particles every frame, as you seem to be doing above, then your counter can simply be
public function updateEmitter( emitter:Emitter, time:Number ):uint { if( _stop ) { return 0; } return 256; }
Then do the compute spectrum in a custom initializer to initialize each particle. You will probably need a static property or two in the initializer to track what's going on from one call to the next. Perhaps just a static ByteArray, which you check in the initialize and if it's empty do another compute spectrum. Then remove a float from the front of the ByteArray and use it each time you initialize a particle. Something like this
public function initialize( emitter:Emitter, particle:Particle ):void { if( ba.length == 0 ) { SoundMixer.computeSpectrum(ba, false); } var baNum:Number = ba.readFloat()*200+200; // adjust particle based on baNum }