I wonder about what road I should go with ParticleSystem
. In this particular case I want to create 1-20 small explosions at the same time but with different positions. Right now I'm creating a new ParticleSystem
for each explosion and then release it, but of course this is very punishing to the performance.
My question is: Is there a way to create one ParticleSystem
with multiple emitting sources. If not should I create an array of ParticleSystem
in init and then use a free one when an explosion is needed? Or is there another approach I haven't thought of?
refer ccparticleexamples.m in your cocos2d library.
It will help for show the different types of particle emitter.
I use a single particle system for each type of effect. So, one for a fire effect, one for a sparkle, one for an explosion, etc.
I use a category to add [enable] and [disable] methods to the base Cocos2D particle systems which looks like this:
ParticleEnhancement.h
#include "cocos2d.h"
@interface CCParticleSystem (particleEnhancement)
-(void)enable;
-(void)disable;
@end
ParticleEnhancement.m
#import "ParticleEnhancement.h"
@implementation CCParticleSystem (particleEnhancement)
-(void)enable {
active = YES;
elapsed = 0.0f;
}
-(void)disable {
active = NO;
}
@end
Then when I want to trigger it I just set the position and call enable. The particle system will spawn a bunch of particles based on the initialization settings. The system can be triggered multiple times in different positions and previously generated particles will behave properly.
The main thing to consider is that you will need a larger particle budget to account for multiple instances of a given effect using a single system.
Also, this works for "triggered" effects, like an explosion but may not work so well for a long running effect like a smoke trail, I haven't really tested that.
I like doing it this way because it means I have fewer particle systems to wrangle and I don't have to deal with setting up a pool of particle systems. The particle system itself does a good job of handling a pool of particles, no need to replicate that again on the system level.
This technique is being used in my app TCG Counter for all of the particle effects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With