2010-10-01 44 views
0

全部 我只是有一个问题,粒子效应并没有出现在所有的时间。我使用Objective C和cocos2d编码为iPhone编码。 下面是有问题的代码。cocos2d粒子效应没有出现

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

+0

您是否尝试过不移动第二个发射器? – jv42 2010-10-01 12:11:19

+0

是的,它的相同的东西,有时它出现并保持在它产卵的地方,其他时间什么都没有 – glogic 2010-10-01 16:01:34

+0

当我删除autoRemoveOnFinish它每次工作。任何人有任何想法为什么这是什以及如何我释放发射器,如果我不使用autoRemoveOnFinish?如果我有多个发射器在飞行中创建,我怎么能释放他们没有autoremoveonfinish? – glogic 2010-10-02 11:12:28

回答

0

尝试这种情况:

  1. 定义在一个局部变量的发射器(.h)中上面的代码之前

  2. 调用此:

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

    这用来检查发射器是一个孩子,并删除它,所以你可以删除emitter.autoRemoveOnFinish所以你的发射器将显示每一次