0

我有这段代码可以让粒子跟随我的 b2body 对象:

-(void)updateMagicFruitParticlePosition:(ccTime)dt{

    if (!gameManager.isPaused) {

         magicFruitParticle.position = especialObject.ccPosition;
    }
    else
       [self unschedule:_cmd];
}

该代码有效,但是当按下暂停按钮并且玩家重新启动游戏时,它会崩溃。从理论上讲,一旦按下按钮,它就应该停止,但它恰好处于更新的中间,即使该方法已计划外。

下面的代码是按下暂停按钮时发生的情况:

-(void)pauseGame:(id)sender{

    if (!gameManager.isPaused ) {

        gameManager.isPaused = YES;

        [gameManager pauseAllSoundEffects];
        [gameManager pauseBackgroundMusic];
        [[CCDirector sharedDirector] pause];

        pauseLayer = [CCLayerColor layerWithColor:ccc4(0, 0, 0, 125) width:screenSize.width height:screenSize.height];
        pauseLayer.position = CGPointZero;
        [self addChild:pauseLayer z:kSecondLayer];

        backgroundPauseA = [CCSprite spriteWithSpriteFrameName:@"BackgroundPauseA"];
        backgroundPauseA.position = ccp(screenSize.width /2, screenSize.height /2);
        [self addChild:backgroundPauseA z:kSuperiorLayer];

        backgroundPauseB = [CCSprite spriteWithSpriteFrameName:@"BackgroundPauseB"];
        backgroundPauseB.position = ccp(screenSize.width /2, screenSize.height /2);
        [self addChild:backgroundPauseB z:kSuperiorLayer];

        [self pauseMenu]; 
    }
}

有没有其他方法可以使粒子效果跟随对象或精灵?或者我怎样才能修复它工作?

任何帮助将不胜感激!

谢谢!

4

0 回答 0