Welcome, Guest
Want to take part in these discussions? Sign in if you have an account, or apply for one below
-
- CommentAuthortimdiacon
- CommentTimeApr 21st 2010
I am trying to create a pool of particles where each particle is a different icon, I also need to add icons to this pool. Currently I have a display object renderer with an emitter. I then have a basic class called iconParticle which takes one var in it's constructor which is a display object which it then adds to it's own display list.
When I need to add an icon to the swarm I add an ImageClass as an initializer, grab a particle from the particle factory and then use addExstingParticles.
emitter.addInitializer(new ImageClass(IconParticle, icon));
var p:Particle = emitter.particleFactory.createParticle();
emitter.addExistingParticles([p], false);
This works great for the first particle but when I try and add a second particle containing a different icon the first one stops moving and is the "rubbed out" as the new one passes over the top of it.
Is it possible to achieve what I am attempting and if so am I going about it completely wrong (I suspect so!)
Any help appreciated :) -
- CommentAuthorbirdsigh
- CommentTimeMay 12th 2010 edited
A better way to do this would be to use the 'createParticles2DFromDisplayObjects' function. This will return an array of particles, created from an Array of DisplayObjects you pass it. Adding this Array of particles to your emitter with the addExistingParticles will then work, and you won't get the 'rubbed out' effect. e.g:
private function addSpriteToParticleSystem(img:DisplayObject):void {
var particles:Array = Particle2DUtils.createParticles2DFromDisplayObjects([img], renderer);
emitter.addExistingParticles(particles, true);
}
Be careful that if you leave the second param in addExistingParticles set to true then all initialisers will be applied to the new particle added. So if you have an initial appearance set in the initialisers then this function will simply create a new particle, rather than add your custom Sprite particle!
Hope this helps!
edit:
Just noticed, there is also the 'createParticle2DFromDisplayObject', which returns an individual Particle2D from a DisplayObject. This may be better suited for what you need. -
- CommentAuthorRichard
- CommentTimeMay 19th 2010
One possible problems is that a single display object can only be in one place at any time. If you use the same icon in two particles, it will be removed from the first particle's display list when being added to the second. It would be better if you export the icon assets in your library, giving each one a class name. Then, instead of using your IconParticle class, just use these class names as the image classes for the particles.
1 to 3 of 3
