SKEmitterNode: Randomize Texture

The basic idea of what needs to be accomplished is an SKEmitterNode that uses a texture atlas rather than a single texture. The concept is that each time a particle is emitted, the texture is randomly selected from one of the textures in the texture atlas. The specification is concrete and must be done in this exact manner, no compromises can be made.


Potential Solutions:

1. Use setParticleTexture: in the update loop.

Problems: This can't be used because using setParticleTexture: alters existing particles, not only newly created ones.

2. Subclass SKEmitterNode to randomize the texture.

Problems: SKEmitterNode is a wrapper for a C++ backing node. It is not possible to alter the behavior of the backing node.


If anyone can suggest alternative methods for accomplishing this, it would be greatly appreciated. This would be relatively trivial to add to SpriteKit but can't be done because it isn't open source. Keep in mind, the specification is concrete so no compromises can be made.


Thanks in advance,

Theronen

I can't think of any possible solution for this.. There is a hack method of course, which is just adding an extra particle emitter for each texture.. but that gets ugly pretty fast.

The issue with adding another particle emitter for each texture is that, as far as I know, there is no method of having them emit in a random order. It would be possible to have four different emitters and reduce the spawn rate by 1/4 but this would result in the textures occuring in the same sequence of 4.

I think it could be done with a shader, where the shader randomly picks from the textures but need to experiment - the hard thing might be getting it to stay the same texture for the life of the particle.

SKEmitterNode: Randomize Texture
 
 
Q