Question

I have this:

-(void)fadeBackground
{
    ccColor4B color = {0,0,0,255};
    CCLayerColor *fadeLayer = [CCLayerColor layerWithColor:color];
    [self addChild:fadeLayer z:7];
    fadeLayer.opacity = 0;


    id fade   = [CCFadeTo actionWithDuration:1.0f opacity:200];//200 for light blur
    id calBlk = [CCCallBlock actionWithBlock:^{
        //show pause screen buttons here
        //[self showPauseMenu];
    }];
    id fadeBack = [CCFadeTo actionWithDuration:2.0f opacity:0];

    id sequen = [CCSequence actions:fade, calBlk, fadeBack, nil];

    [fadeLayer runAction:sequen];

}

How do I stop the actions while the fadein occurs and resume them when the fadeBack occurs?

Was it helpful?

Solution

[[CCDirector sharedDirector] pause]; & [[CCDirector sharedDirector] resume]; will pause and resume the schedulers and actions throughout all the Sprites/Layers or any other cocos2d Nodes.

If you want to pause/resume a particular CCLayer along with children its containing,

////for pausing
[myLayer pauseSchedulerAndActions];
for(CCNode *child in myLayer.children){
[child pauseSchedulerAndActions];
}

///for resuming
[myLayer resumeSchedulerAndActions];
for(CCNode *child in myLayer.children){
[child resumeSchedulerAndActions];
}

OTHER TIPS

To pause, you can use this call, need to call same for each menu in game.

   [self  pauseSchedulerAndActions];
   [menu  pauseSchedulerAndActions];

To resume:

  [self resumeSchedulerAndActions];
  [menu  pauseSchedulerAndActions];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top