Flint Particle System Forum - Particle spawning2010-11-17T10:57:57+00:00http://flintparticles.org/forum/
Lussumo Vanilla & Feed Publisher
Particle spawninghttp://flintparticles.org/forum/comments.php?DiscussionID=88&Focus=400#Comment_4002008-09-10T19:24:18+01:002010-11-17T10:57:57+00:00Joshhttp://flintparticles.org/forum/account.php?u=67
Great library you have here. I've decided to try and use it as it is more complete than the solution I was building, but I was hesitant initially as you have a very different system than the one I ...
See it's for a car game. Whenever the tires skid they spit up a puff of smoke at the tire's location. Similarly when they drive over ground they kick up dust. It isn't practical for me to tie an Emitter to each of the four tires of my 10 cars just for smoke and I'd similarly have to tie different Emitters to each tire for dust seeing as how it is a different color. The conditions of that color are very specific--the surface type the car is currently moving over--so I would need separate Emitters to control the color in different situations. That's 80 Emitters just for basic tire interaction, and I'm likely to want more types of particles for special effects later, meaning even more emitters. With my own solution I simply pass in the position, velocity, and surface type and I can spawn the appropriate particle then and there.
I had originally thought I could implement this with Flint by just collecting the positions of the tires that were skidding into a MultiZone of PointZones, passing this MultiZone into the Emitter at the end of each frame, then resetting the zone again on the beginning of the next. Then I set the Emitter's Counter to Blast and fire it off after collecting all the points. This way I can just use two emitters, one for smoke and one for dust. This works, sort of. I think I'm setting up the Initializers wrong because the particles seem to only stick around for one frame, giving me a flickering smoke puff which follows my tires around.
I realized I have another problem now though, because this method doesn't guarantee there will be a puff generated at each point. It will just spawn the Blast Counter's given number of particles arbitrarily among those PointZones.
This would all be moot if there were an Emitter method to just instantaneously spawn a given number of particles at a given position. The current Emitter behavior is convenient but as I'm illustrating it isn't quite suited to certain applications. I'm curious if you have thought about this or if you see another way to accomplish what I'm trying to do. I've always been fond of particle systems and I seem to recall other solutions tending to include both methods for particle spawning. Both through emitters and an explicit way to spawn or shoot particles from a specified location.
Another thing is that I'll be applying a blur filter over the particles. I had this in my old system and coupled with a small scroll for the wind it looks pretty good. But the Blur filter is pretty expensive, so instead of blurring the whole track I went with a canvas solution similar to how your BitmapRenderer works. Thing is, my stage scrolls as the cars move, so the particles have to be scrolled to compensate for the stage movement. I would just move the canvas as if it were attached to the "camera," and then scroll the contents in the opposite direction. I figure I can accomplish this with a custom Emitter Action yes? One other thing is that I had to erase the edges of the canvas so the blur filter didn't drag any side pixels and effectively create smoke that didn't exist. I could just extend the BitmapRenderer for access to the underlying bitmapData object yes? Maybe this would be something to add, clamping the sides to prevent unwanted filter effects.
Anyway, thanks for your work in putting together this great library for us.]]>
Particle spawninghttp://flintparticles.org/forum/comments.php?DiscussionID=88&Focus=407#Comment_4072008-09-15T13:39:12+01:002008-09-15T13:41:21+01:00Richardhttp://flintparticles.org/forum/account.php?u=1
Hi Josh
What version of Flint are you using? 1.0.4 or 2.0 alpha? I ask because I think 2.0 is better suited to what you're trying to do - the architecture is altered to allow features that will ...
What version of Flint are you using? 1.0.4 or 2.0 alpha? I ask because I think 2.0 is better suited to what you're trying to do - the architecture is altered to allow features that will hopefully help you.
If you use 2.0, you can add all the emitters to a single renderer, which reduces the overhead of creating lots of emitters. You can also use the emitter's addExistingParticles method to create particles by hand when you want to.
I would consider two options...
Option 1
Create custom emitter classes by extending the Emitter2D class with a constructor that adds the necessary initializers, counter and actions for a puff of dust or smoke (see any of the flex examples in version 2 for examples of custom emitters - these are not flex specific) and add the emitter to the single renderer. You'll want some parameters in the constructors to define position and color. Also, add an event listener to listen for the emitter empty event on the emitter and stop it and remove it from the renderer when it is empty. All of this can be wrapped up in one class. You may also want to add a storage mechanism, where each emitter is added to an array when it's created and removed when it completes, so that there's a reference to it and the garbage collector doesn't throw it away.
Then, when you want a puff of smoke or dust, create an instance of the appropriate emitter class with the appropriate parameters and it will create a puff of smoke or dust then remove itself when it's done.
Option 2
Use a single emitter. Create a custom function to create the particles you want and use the addExistingParticles method of the emitter to add the particles to the emitter, where they will be managed until they die. the image explosion example in the version 2 examples uses addExistingParticles.
Personally, I prefer option 1 (which is what I had in mind when designing the library) but either one would work.
Scrolling renderer
For the moving bitmap renderer, I'd be inclined to extend the BitmapRenderer class to create a new BitmapRenderer that redraws its canvas as you require when you change its x and y positions. You can do this by simply extending the existing BitmapRenderer and overriding the setters for the x and y properties - the _bitmapData property is protected, so your class will be able to modify it.]]>