I'm trying to use SKSprite Particle Emitter with Swift.
But I want use a number of different textures in my emitter.
Is it possible to: have many images, and, have the emitter use the images randomly, instead of using only one image?
Thanks
Suppose you designed your emitter with one texture and saved it as "original.sks", and you have an array with the textures called textures
:
var emitters:[SKEmitterNode] = []
for t in textures {
let emitter = SKEmitterNode(fileNamed: "original.sks")!
emitter.particleTexture = t
emitter.numParticlesToEmit /= CGFloat(emitters.count)
emitter.particleBirthRate /= CGFloat(emitters.count)
emitters.append(emitter)
}
Now you have an array of emitters instead of a single one. Whatever you'd do with your emitter, just do it with the array:
// What you'd do with a single emitter:
addChild(someNormalEmitter)
someNormalEmitter.run(someAction)
...
// How to do the same with the array:
emitters.forEach {
self.addChild($0)
$0.run(someAction)
...
}
Of course, you can also subclass SKEmitterNode
so that it contains other SKEmitterNode
children and propagates all the usual emitter methods and actions and properties to the children… depending on your needs.
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