【问题标题】:cocos2d particle effects not appearingcocos2d粒子效果没有出现
【发布时间】:2012-05-10 03:23:19
【问题描述】:

大家好 我只是有一个粒子效果没有出现的问题。我使用objective c 和cocos2d 为iphone 编码。 下面是有问题的代码。

CCParticleExplosion *emitter;

    emitter = [[CCParticleExplosion alloc] initWithTotalParticles:30];
    emitter.texture = [[CCTextureCache sharedTextureCache] addImage:@"particle_bubble.png"];
    emitter.position = ccp(MidX,MidY);
    emitter.life =0.5;
    emitter.duration = 0.5;

    emitter.speed = 60;

    [self addChild:emitter];
    emitter.autoRemoveOnFinish = YES;


    ////////////////////////////////////////////////////

    CCParticleMeteor *emitter2;

    emitter2 = [[CCParticleMeteor alloc] initWithTotalParticles:150];

    emitter2.texture = [[CCTextureCache sharedTextureCache] addImage:@"fire_particle.png"];
    emitter2.position = ccp(MidX,MidY);
    emitter2.life = 0.5;
    emitter2.duration = 2;

    emitter2.speed = 60;

    id emitMove = [CCMoveTo     actionWithDuration:0.5 position:HUD.moonSprite.position ];


    [self addChild:emitter2 z:1];

    [emitter2 runAction:[CCSequence actions:emitMove, nil]];
    emitter2.autoRemoveOnFinish = YES;

此代码在同一个函数中,紧随其后,如图所示。 但有时没有创建第二个粒子效果,我不知道为什么。第一个粒子效果总是没有问题,所以我确定它正确地进入了功能,但有时(几乎 50%)第二个流星发射器没有显示。我尝试使用 z 值来确保它没有隐藏在其他对象后面,并且它似乎不是问题。有人对为什么会发生这种情况有任何想法吗? 谢谢 G

【问题讨论】:

  • 你试过不移动第二个发射器吗?
  • 是的,有时它会出现并停留在它产生的地方,有时什么都没有
  • 当我删除 autoRemoveOnFinish 时,它每次都有效。任何人有任何想法为什么会这样?如果我不使用 autoRemoveOnFinish,我该如何释放发射器?如果我正在动态创建多个发射器,我如何在没有 autoremoveonfinish 的情况下释放它们?

标签: objective-c cocos2d-iphone


【解决方案1】:

我建议使用 71 平方粒子设计器。 http://particledesigner.71squared.com/ 为我做了诀窍。

【讨论】:

    【解决方案2】:

    试试这个:

    1. 在局部变量 (.h) 中定义发射器

    2. 在上面的代码之前调用它:

      if (emitter.parent == self) {
          NSLog(@"em1 released");
          [emitter release];
      }
      
      if (emitter2.parent == self) {
          NSLog(@"em2 released");
          [emitter2 release];
      }
      

      这会检查发射器是否为子级并将其删除,因此您可以删除emitter.autoRemoveOnFinish,这样您的发射器每次都会显示

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-03
      • 2012-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多