I haven’t tried this out but this route looks promising.
Look at the emitter’s setTexture() function. It wants a CCTexture2D to be set so you will need to create one (or obtain one). There appears to be a few different ways you can do this, assuming you loaded a sprite sheet in to the
sprite frame cache, it looks like you do this:
If you’re not using CCSpriteFrameCache then it looks like you can create an image (using CCImage) and use that to create a new CCTexture2D to set for the emitter.
The problem is that although the sprite is used for the particles, all you really get is the shape of the sprite in an arbitrary colour, rather than the natural colours of the sprite.
Aha! It kind of works… The particles start off fine but once they’re recycled and used again they’re just black. They seem to be fading out but I can’t see any setting for this. Any tips?
ParticleSystemQuad *_emitter = new ParticleSystemQuad();
_emitter->initWithTotalParticles(200);
addChild(_emitter, 10);
_emitter->setTexture(TextureCache::sharedTextureCache()->addImage("particle.png"));
// duration
_emitter->setDuration(kParticleDurationInfinity);
// radius mode
_emitter->setEmitterMode(kParticleModeRadius);
// radius mode: start and end radius in pixels
_emitter->setStartRadius(0);
_emitter->setStartRadiusVar(0);
_emitter->setEndRadius(160);
_emitter->setEndRadiusVar(0);
// radius mode: degrees per second
_emitter->setRotatePerSecond(180);
_emitter->setRotatePerSecondVar(0);
// angle
_emitter->setAngle(90);
_emitter->setAngleVar(0);
// emitter position
Size size = Director::sharedDirector()->getWinSize();
_emitter->setPosition(ccp(size.width/2, size.height/2));
_emitter->setPosVar(PointZero);
// life of particles
_emitter->setLife(5);
_emitter->setLifeVar(0);
// spin of particles
_emitter->setStartSpin(0);
_emitter->setStartSpinVar(0);
_emitter->setEndSpin(0);
_emitter->setEndSpinVar(0);
// color of particles
ccColor4F startColor = {0, 0, 0, 1};
_emitter->setStartColor(startColor);
ccColor4F endColor = {0, 0, 0, 1};
_emitter->setEndColor(endColor);
// size, in pixels
_emitter->setStartSize(32);
_emitter->setStartSizeVar(0);
_emitter->setEndSize(kParticleStartSizeEqualToEndSize);
// emits per second
_emitter->setEmissionRate(1);
// additive
_emitter->setBlendAdditive(false);
Maybe someone else will know more about this than I do but I can only guess that the underlying cached texture is being modified (which sounds like a bug). You could try creating a whole new texture every time to see if it would work (though a less appealing solution).
A wild guess : have you tried setting the color variances explicitly?
Yeah I haven’t been able to make any difference yet though. Currently the sprites spawn and weirdly change to black, or spawn black. And their alpha seems to change, for what reason I have no clue.
Well, I think I know what is wrong. I checked the params in Particle Designer and the obvious struck me : the {0, 0, 0, 1} color is BLACK!
So in order to not change the color, the setting should like like that :
As I said : I checked with ParticleDesigner : setting the color to { 1, 1, 1, 1 } on a red particle sprite resulted in this sprite having unchanged color.
Secondly : alpha variance should be equal to 0, because the variance parameters specify how much they can change, so if you put 0 there, such parameter cannot change.
Edit: I’ve added screenshots with examples. On the second one you can see, that with ColorVar.alpha = 1 the particles get some transparency so you can see ones beneath them (the lighter spots).
Well, I think I know what is wrong. I checked the params in Particle Designer and the obvious struck me : the {0, 0, 0, 1} color is BLACK!
So in order to not change the color, the setting should like like that :
>
startColor endColor {1, 1, 1, 1}
sColorVar eColorVar {0, 0, 0, 0}
>
Hope this helps!
I found this out after some tinkering late last night. I too thought this would make them white, but oh well.