cocos2d-iphoneccparticlesystem

cocos2d create CCParticlySystemQuad


This function does nothing, execpt after about 30 seconds the fps begins to go down. I'd like to know what I have to do to display the ccparticle correctly.

Here is my code:

-(void) coccomilk:(CGPoint) p{

   CCParticleSystemQuad *milk = [[[CCParticleSystemQuad alloc] initWithTotalParticles:100 ] autorelease];

   milk.texture = [[CCTextureCache sharedTextureCache] addImage:@"milk.png"];
   milk.emitterMode = kCCParticleModeGravity;
   milk.totalParticles = 100;
   //milk.particleCount = 100;
   milk.life = 0.2f;
   milk.lifeVar = 0.1f;
   milk.startSize = 32;
   milk.startSizeVar = 32;
   milk.endSize = 2;
   milk.endSizeVar = 0;
   milk.angle = 90;
   milk.angleVar = 42;
   //milk.rotation = 0;
   //milk.rotatePerSecond = 0;
   //milk.rotatePerSecondVar = 0;
   milk.speed = 651;
   milk.speedVar= 335.5;
   milk.gravity = ccp(0,-2.72);
   //milk.blendAdditive = NO;
   milk.duration = 0.08;
   //milk.blendFunc = (ccBlendFunc) {GL_ONE,GL_DST_ALPHA} ;
   milk.emissionRate = milk.particleCount / milk.life;
   milk.radialAccel = 0;
   milk.radialAccelVar = 0;
   milk.tangentialAccel = 0;
   milk.tangentialAccelVar = 0;
   ccColor4F color = {1.0f,1.0f,1.0f,0.8f};
   milk.startColor = color;
   milk.startColorVar = (ccColor4F) {0.0f,0.0f,0.0f,0.0f};
   milk.endColor = color;
   milk.endColorVar = (ccColor4F) {0.0f,0.0f,0.0f,0.0f};
   milk.position = ccp(p.x,p.y);
   //milk.posVar = 0.0;
   milk.sourcePosition =  ccp(p.x,p.y);
   milk.visible = YES;

   [self addChild:milk z:2];

   milk.autoRemoveOnFinish = YES;
   [milk release];
   //[self performSelector:@selector(clearSprite:) withObject:water afterDelay:0.4];
}

Solution

  • There are more mistakes:

    1. There's a wrong emissionRate. You're counting it from the actual number of particles, what's 0 in the time of initialization. Your emissionRate is 0 which means no particles will be emitted. The correct calculation is:

      milk.emissionRate = milk.totalParticles / milk.life;
      
    2. There're too many releases. It will crash on the last release (autoRemoveOnFinish), so remove the last [milk release] from your code. Your particle system will be released after it's life period when it finishes - thats what autoRemoveOnFinish is for - so you don't need to do it manually.