Welcome, Guest
Want to take part in these discussions? Sign in if you have an account, or apply for one below
-
- CommentAuthoricd2k3
- CommentTimeJul 24th 2008
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 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! -
- CommentAuthorRichard
- CommentTimeJul 25th 2008
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. 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. -
- CommentAuthoricd2k3
- CommentTimeJul 25th 2008
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 correct?
Your dedication to this class is insane, I really want to understand it from top to bottom -
- CommentAuthoricd2k3
- CommentTimeJul 25th 2008
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 new particle (count++) that it's making. This is what I have now and I commented out the extra functionality I want it to have.
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 -
- CommentAuthoricd2k3
- CommentTimeJul 25th 2008 edited
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 the values for the whole emitter? -
- CommentAuthorRichard
- CommentTimeJul 27th 2008
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. Note that you can add your own properties to the particles, by adding them to the particle.dictionary object, which may also be useful to you.
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 bepublic 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 thispublic 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
}
N.B. I haven't tested this at all.
1 to 6 of 6
