cocos2d创建CCParticlySystemQuad

时间:2012-08-24 19:19:27

标签: cocos2d-iphone ccparticlesystem

此功能不执行任何操作,除非在大约30秒后fps开始下降。我想知道我必须做些什么来正确显示粒子。

这是我的代码:

-(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];
}

2 个答案:

答案 0 :(得分:0)

我建议您尝试使用ParticleDesigner,这是一个轻量级应用程序,允许以图形方式设计您需要的粒子,一旦您满意,生成cocos2d可以管理的配置文件。 http://particledesigner.71squared.com/

答案 1 :(得分:0)

还有更多错误:

  1. 有一个错误的emissionRate。你是根据实际的粒子数来计算的,在初始化时它是0。您的emissionRate为0,表示不会发射粒子。正确的计算是:

    milk.emissionRate = milk.totalParticles / milk.life;
    
  2. 发布的内容太多了。它将在最后一个版本(autoRemoveOnFinish)上崩溃,因此从代码中删除最后一个[milk release]。你的粒子系统将在它完成后的生命周期后释放 - 这就是autoRemoveOnFinish的用途 - 所以你不需要手动完成。