0
votes

So I'm developing an iPhone game using cocos2d.

I'm using pushScene to transition from my gameplay scene to a main menu scene because I want the player to be able to resume gameplay from the main menu if they choose. If they do choose to resume, I use popScene.

The trouble seems to be that if events are "incomplete" at the time when the gameplay scene is pushed, when the scene is popped, those events do not complete. What's worse, they leave artifacts on the scene that don't clear by themselves.

Examples: particle explosion effect (particles get "frozen" and don't dissipate as designed), sprite fade-out effect (sprite remains visible at a certain level of transparency).

I guess I would have expected popScene to resume the scene exactly as it was when the scene was pushed, but it seems to be "abandoning" currently-running actions.

How can I achieve my goal?

2

2 Answers

0
votes

I suggest you to add both game play layer and main menu layer to the same CCScene as children rather than using pushScene and popScene. When you need to show the menu, change the visibility of the layers and pause all the contents in your game play layer. You can try these methods to recursively pause/resume activities of your game layer:

- (void)pauseSchedulerAndActionsRecursive:(CCNode *)node {
    [node pauseSchedulerAndActions];
    for (CCNode *child in [node children]) {
        [self pauseSchedulerAndActionsRecursive:child];
    }
}

- (void)resumeSchedulerAndActionsRecursive:(CCNode *)node {
    [node resumeSchedulerAndActions];
    for (CCNode *child in [node children]) {
        [self resumeSchedulerAndActionsRecursive:child];
    }
}

call something like:

[self pauseSchedulerAndActionsRecursive:gamePlayLayer];
0
votes

I used Hailei's code but created a category that works OK for me.

CCNode+additions.h

#import "CCNode.h"

@interface CCNode (additions)
-(void)pauseSchedulerAndActionsRecursive;
-(void)resumeSchedulerAndActionsRecursive;
@end

CCNode+additions.m

#import "CCNode+additions.h"

@implementation CCNode (additions)
-(void)pauseSchedulerAndActionsRecursive {
    [self pauseSchedulerAndActions];
    for (CCNode *child in [self children]) {
        [child pauseSchedulerAndActionsRecursive];
    }
}
-(void)resumeSchedulerAndActionsRecursive {
    [self resumeSchedulerAndActions];
    for (CCNode *child in [self children]) {
        [child resumeSchedulerAndActionsRecursive];
    }
}
@end

So when pausing, call pauseSchedulerAndActionsRecursive on your game node before you add a "pause menu node" to the game node (else the pause node will be paused too and thus unusable).