I am new to Spritekit. Just starting to make my 3rd-4th game. So I'd like to know what is the correct way to use SKEmitterNode programmatically.
In particular what is the correct practice if I want to have multiple particles in my game - jet engine fire, and also multiple explosions when bullet hits enemy ship.
Do I keep on creating new SKEmitterNode and adding it to the scene or do I add a single global EmitterNode and change its properties in the update function?
// FIRE ENGINE
SKEmitterNode *_myEmitter = [[SKEmitterNode alloc] init];
// codes..
[self addChild:_myEmitter]; // add to scene
// EXPLOSION
SKEmitterNode *_myEmitter = [[SKEmitterNode alloc] init];
// codes..
[self addChild:_myEmitter]; // add to scene
OR
// IN INIT METHOD
_myEmitter = [[SKEmitterNode alloc] init]; // global variable
// codes..
[self addChild:_myEmitter]; // add once
// IN UPDATE
//when explode
_myEmitter.particleTexture = [SKTexture textureWithImageNamed:@"explode.png"];
... modify code
//when engine fire
_myEmitter.particleTexture = [SKTexture textureWithImageNamed:@"fire.png"];
... modify code
?
You can do it either way. In my game I had different emitter types for different types of effects. The reason for that is because each of my emitter's properties would be so different that it wouldnt make sense to generalize. The other reason is because I might need to have multiple emitters on the screen at once.
If you know that most or all of your properties are going to be the same and you're only going to use one emitter at a time then you can just change the texture.
Basically it depends on what youre trying to do. There isnt one best practice. I do recommend using the particle editor though. Just must faster to tweak things visually and you can always change the properties programmatically later on.